• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

GML Flipping bullet on off center barrel?

Annthoni

Member
Im new to game maker 2, and well creating games in general, ive been following some tutorials and decided to be abit creative early on by designing a off center barrel gun for my sprite, when the bullets fire to the right they seem to match the barrel, but they dont when the sprite flips to the left, can anyone help with this?

///Create bullet
var dir = point_direction(x, y, mouse_x, mouse_y);
var xscale = (mouse_x > x)*2-1;
var gun_x = x-4*xscale;
var x_offset = lengthdir_x(30, dir);
var y_offset = lengthdir_y(30, dir);

instance_create_layer(gun_x+x_offset, y+y_offset, "Instances", o_bullet);
this is the code ive been using
 
so i can't answer this question without having more information. Let me ask you this, where is the origin on the bullet sprite, and where is the origin on the gun sprite?
 

Annthoni

Member
I'm not quite sure, this is my first time making a game, been following along the YouTube tutorials, how would I find the origins?
 

Annthoni

Member
How would I flip the direction so that it would mirror left with right in the step? The bullets are aligned when the sprite fires right, they misalign when the sprite image flips to face left.
 

Jakylgamer

Member
assuming the bullets are being rotated and the sprites origin offset isn't centered , try flipping the yscale value of the bullet when mouse is < x
example:
Code:
var bullet = instance_create_layer(x,y,layer,obj_bullet);
if mouse_x < x {
   bullet.image_yscale = -1;
} else {
   bullet.image_yscale = 1;
}
 
Top