Animations not playing during Pathfinding

I have an enemy in which when the player gets within a certain distance of them (I’m using 75px, for now), the enemy’s Pathfinding behavior will be activated and they will move toward the player. This all works fine, except once the Pathfinding behavior is activated, the enemy’s animations are usually not playing at all. They will be stuck in the first frame of their animation while moving on the path toward the player. I’m using the Angle of Movement condition to check for the angle of the pathfinding enemy’s current movement, then setting their animation based on that angle with a tolerance of 89 degrees (since the game only has 4 directions of movement).

I’ve been playing around with this for hours now, and I can’t figure out why the 2-frame animation of the enemy based on the direction they’re moving in won’t play (or the wrong one will play at times, if at all). Here is the code I have right now:

In other words, when the enemy’s Pathfinding behavior is active (variable IsPathfinding=true), I want them to move toward the player (Link) and change their animation (AND play the animation) while they’re moving in that direction, with a tolerance of 89 degrees (for 4-direction movement, with a different animation for Up, Down, Left, and Right).

Why is the animation not playing? It’s usually stuck on the first frame, despite the enemy’s pathfinding movement working fine and while they animation changes properly most of the time, it will stay at the first frame instead of playing the looping walking animation for that direction.

Can you guys please help me out here? This is driving me insane trying to figure this out. Thanks in advance!

I believe the tolerance is plus or minus not total. So, instead of 90 or 89 try 45 or 44.

Value 90, tolerance of 45 would be 45 to 135.

I’ve played around with the tolerance values quite a bit in the hours I’ve been experimenting, and had them at 44, 45, 10, 2, 0, etc. The result was the same, with the animations simply not wanting to play despite the pathfinding behavior working as expected.

In other words, the enemy’s animation changes to the proper direction and moves to the player position properly when I use the Angle of Movement condition, but once it does, it will be stuck on the first frame of its 2-frame walking animation. So having it facing the proper direction isn’t so much the problem as is having the animation play once the enemy is facing the proper direction.

I use an almost exact strategy in this other post except it uses a random destination instead of chasing link.

IDK if you also need to use play animation I did in my example but I’m not positive it’s needed but mine works. I believe I also have the animations set to loop.

The more I play with it, I’m now noticing something else. The animation will play properly only in 1 of the 4 directions. From what I can tell, whichever Angle of Movement condition I have listed first in the code, that is the one direction in which the animation will play properly. Once the enemy changes to another direction while pathfinding, the other animations don’t play and they stay frozen at the first frame.

I tried using Play the Animation, but haven’t had any luck with that either. I can’t imagine what could be causing this!

Update: I just figured something else out. So, I have the basic “patrol” movement of the enemy Lizalfos set up to change direction with an object timer “Movement”. I had the thought to disable all those movement events and then test the pathfinding while they’re disabled, and lo and behold, the animations work properly while pathfinding when the timer-based patrol movement events are disabled. So it’s something to do with the following code which is causing the animations to not work while pathfinding is active:

So I guess now we have to figure out how to get the pathfinding animations to work while still having these basic “patrol” movements and animations…any thoughts?

If that’s interfering with the pathfinder than maybe the time < and timer >= need the isPathfinding is false condition.

Hi tjv, I had the same problem as you recently, I just could not get the animations to consistently change. I actually switched from using the pathfinding behavior to the Navigation mesh pathfinding behavior extension by D8H:


One part of the extension shown below allows for animations to automatically change depending on direction with no events. It has worked perfectly for me. You just name the animations a certain way and that's it. Perfect.

image

You’re right! Once you add that condition to the timer conditions, the animation plays as intended in each direction.

I also stumbled upon an alternate solution. When Link is within a certain distance of the enemy and IsPathfinding is set to true, I paused the “Movement” timer and set the variable Direction=0 (no forces apply to that variable). So it essentially sets the Direction variable to a number that has no force/animation applied to it and now no “Movement” timer is counting. Then, the pathfinding animations play exactly as I intended them to when the enemy’s direction changes.

Thank you so much for your input and ideas, Keith_1357!!!

1 Like

I haven’t heard of that extension, but from what you’ve said, I will definitely check it out once I add a couple more pathfinding enemies to the game!

When I tried the Mesh Animator with the mesh pathfinder, I get a black screen and an error.

“Internal crash: TypeError: gdjs.evtsExt__NavMeshPathfinding__NavMeshPathfindingAnimator.NavMeshPathfindingAnimator.prototype.onCreatedContext.GDObjectObjects2[i].getBehavior(…).diagonalsAllowed is not a function”

I don’t know if I’m missing something but it says the behavior isn’t attached
image

I don’t have enough context to know about the top down movement error you’re getting, I have the object set to pathfinding only and use cursor position for the destination for testing purposes. But what I can say is the black screen…diagonals allowed error happened for me too.

When I was setting things up for testing I left ‘Number of directions’ on 0 but I didn’t actually have 4 or 8 animations with the linked name. I only had three animations and would get that same error.

1 Like

It’s good to hear it’s not just me. Unless I forget, I’ll report it later.

When I discovered the reason for the error I had a ‘it’s not them, it’s me’ feeling. I hadn’t set things up correctly, therefore I got an error. But yeah having enough info to avoid the error can only be a good thing.

1 Like