So I have created an enemy object and given it pathfinding behavior, with no rotation and no diagonals. I have 4 sprite animations for 4 direction of movement. I want the object to change animations based on which way it is moving i.e play the ‘left’ animation when the object is moving left.
What condition do I use to check which direction the object is moving?
Hi there, I haven’t tried this, but…
When the object is moving, create/modify an object variable of the enemy object and change the value to “Average angle of the forces”. Press the Sigma 123 button to type “force” and find it from there.
If the result is the angle it’s moving, you might be able to check the angle and change animation by the value of the variable.
Thank you for your response. I just tried doing what you said. But it didn’t seem to work. I opened the debugger and checked, but the value never changes.
For pathfinding, force seem not used.
It’s just an interpolation of positions.
So position and angle values change.
For get the direction you can get the angle of the object.
Let me know if it’s correct
Thanks for the suggestion. Since I plan on using sprite animations for each direction, I turned off “rotate object” in pathfinding behavior. So angle of object does not give anything.
But that gives me an idea. Maybe I can use an invisible rotating object for pathfinding and make the enemy object follow that invisible object. I will see if that works.
Thanks a lot. I managed to make it work
Hi, please, can you tell me how did you solve it. I haven been trying to do this for a long time now.
Sure. This is what I did:
At first I made an object called pathfinder which has no sprites. Then I gave it pathfinding behavior. I disabled diagonal movement since my enemy does not have sprites for it. I also turned the rotation speed up.
Then I did the following:
The enemy object follows the location of the pathfinder object. The angle of rotation of pathfinder is stored in the scene variable enemy_angle
The formula I used on line 3 ensures that the value of enemy_angle is always 0, 90, 180 or 270
Afterwards, the animation of enemy is set based on the value of enemy_angle.
To summarize, the target object sits on top of an invisible pathfinding object and uses its angle to set animations.
Thanks! This is very helpful