• 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 8 Directional Movement with Enemy object help

I'm looking to have my enemy object moving randomly in 8 directions with it facing & moving in the same direction. I'm using the enemy object as a target so my goal is to hit it, thus why I need it to move randomly.

Step Event:

switch (direction div 90)
{
case 0: sprite_index=sprite_Thunder_Viking_Running_Right; break; //Change these sprite names to the ones in your game!!!
case 45: sprite_index=sprite_Thunder_Viking_Running_Up_Right; break;
case 90: sprite_index=sprite_Thunder_Viking_Running_Up; break;
case 135: sprite_index=sprite_Thunder_Viking_Running_Up_Left; break;
case 180: sprite_index=sprite_Thunder_Viking_Running_Left; break;
case 225: sprite_index=sprite_Thunder_Viking_Running_Down_Left; break;
case 270: sprite_index=sprite_Thunder_Viking_Running_Down; break;
case 315: sprite_index=sprite_Thunder_Viking_Running_Down_Right; break;
}


Alarm: [0]

direction=irandom_range(0,365)
speed=2
alarm[0]=60


I'm guessing that the Case is the degrees it should be moving in but, it isn't facing in the direction it should be moving in. Can someone assist?
 

MaxLos

Member
Well for one your using div incorrectly here. Div returns the amount of times a number can divided by another. So if your direction was 270, for example, your switch statement would be checking for a case of 3. Also, why are checking for up to a direction of 365? Did you get the degrees and the amount of days in a year mixed up? huehue
Also.. you should be using choose instead of irandom_range since you want specific directions.

Try this
Code:
switch (direction)
{
case 0: sprite_index=sprite_Thunder_Viking_Running_Right; break; //Change these sprite names to the ones in your game!!!
case 45: sprite_index=sprite_Thunder_Viking_Running_Up_Right; break;
case 90: sprite_index=sprite_Thunder_Viking_Running_Up; break;
case 135: sprite_index=sprite_Thunder_Viking_Running_Up_Left; break;
case 180: sprite_index=sprite_Thunder_Viking_Running_Left; break;
case 225: sprite_index=sprite_Thunder_Viking_Running_Down_Left; break;
case 270: sprite_index=sprite_Thunder_Viking_Running_Down; break;
case 315: sprite_index=sprite_Thunder_Viking_Running_Down_Right; break;
}
Code:
//Alarm[0] Event
direction = choose(0,45,90,135,180,225,270,315);
speed = 2;
alarm[0]=60;
 
Top