• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [SOLVED]Shooting from tip/barrel of gun

M

mateus souza

Guest
hello, I'm doing a top down project, however no matter what I do the bullet keeps coming out of the gun barrel, could anyone help me? I'm learning to use the game maker yet and I do not know some basic things.

my sprite = x=128 y= 85
origin = x=40 y=49
gun tip = x=119 y=62

global mouse left button =

if (!fire){
fire = true
alarm[0] = cooldown;
instance_create(x+lengthdir_x(77,image_angle),y+lengthdir_y(77,image_angle),obj_bullet);
}sprite.png shooting.png playershoterror.png
 
D

DarthTenebris

Guest
however no matter what I do the bullet keeps coming out of the gun barrel
Sounds about right, unless that's not what you want, in which case you should probably tell what you want it to do instead.

3rd image: Oh wow, turns out it isn't coming from the barrel, seems more like from the center of the player sprite.

Perhaps some clarifications on what you want exactly might help others help you?

Anyways, for now I'll assume you want your bullets to come out from the barrel. If that's the case, try finding the coordinates of the barrel relative to the origins from the sprite editor, and use those coordinates to create your bullets (relative to the player as well of course).

Hope I helped :)
 
M

mateus souza

Guest
I need the shot to come out of the gun barrel but I can not do it, I tried to use the diagram but I can not understand it, I tried it in several ways but it still did not work. ,:(
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Your code is fine, just offset the image_angle by a few degrees, eg:

Code:
var_x = x + lengthdir_x(77, image_angle - 10);
var_y = y + lengthdir_y(77, image_angle - 10);
instance_create(_x, _y, obj_Bullet);
If that's not correct, just change the "10" value for 8, or 15 or whatever works. :)
 
M

mateus souza

Guest
Your code is fine, just offset the image_angle by a few degrees, eg:

Code:
var_x = x + lengthdir_x(77, image_angle - 10);
var_y = y + lengthdir_y(77, image_angle - 10);
instance_create(_x, _y, obj_Bullet);
If that's not correct, just change the "10" value for 8, or 15 or whatever works. :)
OWWWWWWW THANK YOU, it's more complicated than I thought, I would not be able to figure it out by myself, THANK YOU again,Now I can sleep peacefully :).
solved.png
 
Last edited by a moderator:
Top