# Drag And Drop Enemy moving in only 4 directions? (DnD)

Discussion in 'Programming' started by Nick2820, May 17, 2019 at 11:06 PM.

1. ### Nick2820Member

Joined:
Friday
Posts:
2
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 ^^

2. ### TheSlyMember

Joined:
Jan 16, 2017
Posts:
832
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?

3. ### BrainwormMember

Joined:
Nov 24, 2017
Posts:
9
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.

4. ### TheouAegisMember

Joined:
Jul 3, 2016
Posts:
6,512
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.

5. ### BrainwormMember

Joined:
Nov 24, 2017
Posts:
9
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.

6. ### Nick2820Member

Joined:
Friday
Posts:
2
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.

File size:
302.2 KB
Views:
18