• 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!

GML Flipping bullet on off center barrel?

A

Annthoni

Guest
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
 
D

dannyjenn

Guest
Are you sure you have both sprites' origins set correctly?
 
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?
 
A

Annthoni

Guest
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?
 
A

Annthoni

Guest
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