A* Pathfinding Project

How to cancel movement?


I have a feature in my game that should cancel the movement of the AI by setting the target in the “AIDestinationSetter” to null. Even though I successfully remove the transform as the target the the AI will still go the the position the target was set to instead of stopping. I was wondering how I could cancel the movement of the AI mid path?



You can set ai.destination to an invalid value.

For example

var ai = GetComponent<IAstarAI>();
ai.destination = new Vector3(float3.PositiveInfinity, float3.PositiveInfinity, float3.PositiveInfinity);

If you also want to remove the current path the agent is following you can call