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

Windows Enemy stuck flipping x_scale

N

Nick Craven

Guest
I created an enemy that moves to hover above the player and shoot at it, and have the x_scale set to flip so that its always facing the player, but once it reaches the destination it flips back and forth between the negative and the positive x_scale. I've tried a few ways to get it to stay facing one way or the other, but can't figure it out.

//awareness
if (distance_to_object(obj_player) < 300)
{
move_towards_point(obj_player.x,obj_player.y-90,spd);
}
image_angle = 0;

//direction
if (direction>90 && direction<270 )
{
image_xscale=2
}
else
{
image_xscale=-2
}
 

obscene

Member
Maybe stop moving it once it's close enough...

if ( (distance_to_object(obj_player) < 300)
&& (distance_to_object(obj_player) > 30) )

I can't remember but you might need to set speed back to 0 again as well.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Yeah, if it reaches close enough to the goal point it will just undulate forth and back over it incessantly. Do something special when it's close enough to the goal to get the desired behavior. (I say "close enough" because typically you never exactly reach the goal because of various floating point and number divisibility shenanigans, so the criteria for reaching the goal usually is "be within your max move speed distance of the goal")
 
N

Nick Craven

Guest
Thanks for the help! I had it slow down when it gets close enough and now it looks much better!
 
Top