I’m working on making a mobile game that doesn’t have an on-screen gamepad, so I’m trying to make it so when I touch or click an object, my character will walk to it and interact… go to next room, open a chest, inspect an object, etc. I figured using pathfinding would get the character to where I need him to be, but I seem to need to create an event to check which direction he’s moving and set the animation accordingly with the 4-direction animations I have.
Also, how can I constrain pathfinding to only 4 directions without diagonals, or would it be easier or better to do all of this some other way?
EDIT: I figured out the 4-directions only. It was already set for that, just the wrong grid size made it move diagonally for a moment.
The Pathfinding behavior is changing the angle of the object to move the object in to different directions.
Without diagonals:
Angle 270 = Up
Angle 90 = Down
Angle 0 = Right
Angle 180 = Left
If you are using 8 Direction Animation type it is playing the correct animation based on the angle of object so you can do the same.
You can check the angle of the object to change animation and you can check if the object is reached it destination to see if it moving, if it not reached then probably it moving:
[code]Angle of object = 0 and Object is NOT reached it destination:
Object is moving Right
Play Walk Right Animation
Angle of object = 0 and Object is Reached it destination:
Object is facing Right but doesn’t move
Play Facing Right Animation[/code]
Thanks for replying, but it doesn’t seem to have worked. It acts like it doesn’t change angle while moving and always at 0. I attached the events that I’m working with. Doing a test run, it makes the character always face right, even when moving other directions.
It’s not a direct top-down character, so it’s not set to rotate. That’s probably why testing the angle isn’t working and why I wanted to test the direction of movement. I tried “Angle of displacement” under All Objects > Movement, even with a 45 degree tolerance, but it acts like it doesn’t see the pathfinding movement as regular movement.
Indeed.
I was wrong about the angles. 
The angles are moving from -90 to 180 at least this is the values that Object.Angle() expression returns when the object is rotated by the Pathfinding behavior:
0 = Right
90 = Down
180 = Left
-90 = Up
The other thing I was wrong about, I think the values under the hood are decimal numbers so the angle of the object never going to be exactly, 0,90.180…etc It always more or less like 90.0001 or 179.9998 or something.
I guess but really I don’t know, I hope someone else able to tell why it doesn’t work because I think it should. The object is rotating = it angle changing. It seems straight forward to check it angle along with destination reached to get the direction of movement. If it doesn’t work, the only thing I can think of the value of angle returned is not exactly 0,90,180…etc but a decimal value.
What you can try to do is to check a range of angle for each side instead of exact value.
Alternatively you can also store the X and Y position of the object in variables, update the variable every frame or so, and compare the value of the variables every next frame with the current position of the Object, if it different, the object is moving.
If previousX < currentX : Object is moving Right
If previousY > currentY : Object is moving Up
But really, if you need the direction of movement only to play animations, you can change the animation type to be “8 Directions”, and you can add different animations up to 8 Directions.
Make sure the animation is set to loop and it going to change and play the animations automatically based on the angle (direction) of the object:

If you want to know if the object is moving, you can check if destination is reached.
For example, you can use Animation 0 to be stand animations for different direction and Animation 1 could be walking animations for different direction and you can use destination reached to check if object is moving:
[code]If Destination is NOT reached : (object is moving)
Play Animation 1 (which is an 8 Directions animation so it going to play different animations for different directions)
If Destinations is reached: (object is not moving)
Play Animation 0 (which is an 8 Directions animation so it going to play different animations for different directions) [/code]
1 Like
Thanks. Setting 4 of the 8-direction animations and turning on rotation in pathfinding worked.