• 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 Visual Enemy moving in only 4 directions? (DnD)

N

Nick2820

Guest
Hey everyone,

So I'm trying to make my enemy move only up, down, left and right
I already got it to follow the player, but it just rotates to and moves in every direction
If anyone could help me out that'd be great ^^
 

Slyddar

Member
So do you want the enemy to move on a grid? And how do you want it to move, i.e freely, or move to where the player is?
What does your follow code look like now?
 
B

Brainworm

Guest
I am not sure how to do it with DnD, but there should be a way to set the angle of the movement of an object. This tutorial shows (at around 6:50) how you can rotate Objects in DnD:


Maybe this is the right way to do it, but I am not sure, since I use GML.
What you could do then, is always add/subtract the rotation by 90, this should restrict the rotation into 4 directions, up, left, right and down.
 

TheouAegis

Member
What's the code you currently have for moving the player?

If you're using direction, I think you can use Change Variable and set direction to (direction+45) div 90.
 
B

Brainworm

Guest
What's the code you currently have for moving the player?

If you're using direction, I think you can use Change Variable and set direction to (direction+45) div 90.
But wouldn't that return a wrong value? Let's say the direction is 60, then direction + 45 would be 105 and 105 div 90 would return 1. You could use it by multiplying the result with 90. So if you would make it like this ((direction+45) div 90 ) * 90 you should only get the values 0, 90, 180 and 270.

But this, and what I recommended would only restrict the direction to 4 directions, the object could still move as far or short as it wants. If you want grid movement as TheSly asked, so that your enemy can only walk on certain fields, it would be a different thing because you first have to set up a grid.
 
N

Nick2820

Guest
right now this is what I've got
right now he walks directly towards the player, but for the style of game I'm making I want him to make a detour.
say the player is south-west of the enemy, I want the enemy to first walk to the right and then down and not directly diagonally.
 

Attachments

Top