(Solved) Pathfinding animation problem in 8 directions

Hello everyone! I’m creating an isometric RPG. It was a big problem to get the animations of enemies with the pathfinding behavior in all 8 directions to work correctly. I managed to do it in 4 directions. But with the movement along the diagonals, the problems remained. The animation does not play - it freezes on the first frame. Of course, they are cyclical, and all the settings are applied to them the same as to working animations. I would be very grateful if you could help me figure out exactly what the problem is.

1 Like

While this may not be the source of your main issue, please note:

Any time you are doing any animation events, they must have the “Trigger once” condition, or some other condition that ensures they only occur once.

Right now your events are going to set the animation every frame, which resets it to animation frame 0.

You should add trigger once to each of your subevent’s conditions, and see how it behaves afterwards.

1 Like

Thank you very much for your reply. I tried to do as you said, but it didn’t turn out what I should have expected. I attach a gif and a screenshot. Now the animation that is played first according to the conditions is played forever. I got the same result when I added a trigger to the main event, and not to each sub-event. I’m new to this engine, so please don’t judge strictly if I’m doing something obviously wrong.

Запись экрана 2022-04-21 в 23.07.51

No worries. Event order matters a lot in this case, so you’ll (normally) want Trigger once to be at the bottom of each event conditions.

With the current setup it could be making it behave very oddly since it’s happening before the rest of the conditions.

Edit: Actually, looking deeper at this you’ve got a lot of conflicts in your events that deal with the animations. You have a situation where the goblin could be at Variable X - 64 but also at Y -64.

Your current movement setup likely isn’t going to do what you’re wanting it to do. You probably need to not go based off X/Y positions and instead go off angle to a position. You’ll want to use the “Compare two numbers” event conditions, then use the expression builder to find the “Angle to position” expression.

Angles start from the rightmost/eastmost direction at 0 degrees, then go around clockwise. (0 is right, 90 is down, 180 is left, 270 is up, etc).

1 Like

I also tried to lower the trigger for each subevent below, and this helped in a sense - now only diagonal animations are played.
I tried to create conditions with angles, spent the whole day on it, but it didn’t work out. Maybe you have an example of such an event?

1 Like

Something has changed in GDevelop with the setting animation. If you set an animation and it’s the same animation as before, then it won’t reset tot eh first frame - it just keeps playing.

@Hezeper, try renaming your animations to the angle they represent (0 for right, 45 for down-right, 90 for down etc) :

And then use the following to get the angle and set the animation :

I use round because sometimes the angles aren’t exactly a whole number, and I use mod in case the angle is 360.

I also added a timer because otherwise the animation seemed to flicker, as it quickly changed angles along the path.


This is the only example I know of that actually gets this to work, thank you sooooooooooooooo much MrMen.
I had to add the highlighted section though as the way you had it gave me an error. Here’s my event for 4 directions. Didn’t do the mod or timer thing yet, will think about that later. I’ve only tested this in my test mouse destination game, not my actual one yet but fingers crossed.

1 Like

Yeah, I’ve done mine a little differently and set the animation name to the angle it represents, whereas you’re, changing the animation number based on the angle. Both work.

In your snip, however, you should simply use Variable(PlayerAngle). It’s a simpler/better way of writing ToNumber(VariableString(PlayerAngle))


Good callout, I forgot this started happening, but I don’t know if it’s intentional or when it changed. I’ll dig into that.


Thank you, MrMen , for the detailed description. I will try this method and report the results!*

@MrMen, I’m confused by the mod thing.
Say the angle was 135 and the end result should be it switches to animation 3.

Without the mod:
135 / 45 = 3. Bingo.

With the mod:
135 / 45 = 3
And then 3 * 45 = 135
And then 135 mod 360 is 135

Am I reading it wrong? I also outputted the variable to a text object and it gave results similar to what I’ve shown here.

1 Like

Friend, do you understand that the topic I started is not the first one dedicated to this problem on the forum? I counted at least 7 of the same or similar questions. People called it an impossible task, I myself had killed the whole previous day for it and had already given up, but… Everything works, your way is perfect. I will placed a monument to you in my city, thank you very much! Thanks also to everyone involved in the discussion!
I think the question can be considered closed

1 Like

Nope, that’s correct. The mod is part of my my standard practice with angles to keep them between 0 and 359 (usually it’s mod(angle + 360, 360) to keep the angles positive too). The angle 360 can cause an issue unless there’s a 9th animation named “360”,