Support Forum

A* AI getting stuck when chasing target

I use A* ai because navmesh agents don’t work with tile maps. But I have an issue with my a* ai where they just randomly stop chasing their target and just stay still. The target is the player, and what happens is they’ll be chasing the player and then all of a sudden they will just stop moving towards the player. Normally, I have a script that tells them when to move or stop through states (Idle, Follow, Attack, etc.), but even with those scripts completely disabled/removed, the ai will just freeze out of nowhere. I can see that their “desired velocity” is not 0, so they’re not actually stopped, but more so like “stuck.” It seems like they are trying to move, but cannot. I did notice that if anything pushes or moves them in the slightest, they will become unstuck until the bug occurs again.,

In this screenshot below, you can see that the enemy’s velocity is greater than 0, but the enemy isn’t moving (hard to see because its a screenshot), but just imagine that they are just staying still. You can also see that the a* ai is still drawing rays towards their target, so they are still able to update their path towards the player, but just can’t move. You can also see that I have scripts like “EnemyController” and “EnemyMovement” which I thought would cause this issue, but the problem still occurs even with all my scripts removed (only keeping the scripts that AStar requires like AIPath, Seeker, and AI Destination Setter.

These are the values that I put inside of the AIPath script that comes with AStar:

Also my enemies do have a rigidbody, if that matters. Thank you

Your AI Destination Seter Target is set to None in th screenshot. Drag a gamobject into it and your agent should start going for it.

I forgot to mention, I do set the target during runtime. When the freeze bug occurs, the enemy does still have a target. I even tried setting the target again when the enemy stopped moving, and the the enemy remained still anyways. It’s a weird bug lol. The second screenshot wasn’t taken at the same moment as the first screenshot, apologies for that.

Sorry I’m a beginner at all this and am not sure. Just spotted that as I had the same issue before.
I add loads of Debug.Log(" " + ); to the code which helps highlight the point of failure.
Also you can check if the path is still valid by calling into IASTARAI script.

This might be of help I hope: IAstarAI - A* Pathfinding Project

Maybe the search path needs to be recalculated after something changes to block the original path?

Hm, I don’t think I tried checking if the path was valid. I’d have to try that later. Thank you.

1 Like