• 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 move enemy left and right

tbrides

Member
hello,
I'm trying to get an enemy object to move just left and right

here is my code in the Step event:

if(x<=room_width-100){

x+=flySpeed; //flySpeed is a variable in the Create event

}else{

x-=flySpeed;
}

But it's sticking to the right side of the room and not moving back
 

TheouAegis

Member
Yeah because as soon as x is greater than room_width-10, it moves back flyspeed, so then it's less than room_width-100. So then it moves right flySpeed. But then it's greater than room_width-100, so it flies left flySpeed. Now it's less than room_width-100 again, so it flies right...

if median(x,100,room_width-100) != x
flySpeed = -flySpeed;
x += flySpeed;
 
Top