- Home /
NavMeshAgent.isStopped = true but is still moving?
In the debug log it is true but the enemy still is following its path towards me? Within Update() if(hasReachedDestination()) { agent.isStopped = true;
}
else
{
agent.isStopped = false;
}
hasReachDestination Code
bool hasReachedDestination()
{
Debug.Log(Vector3.Distance(transform.position, agent.destination) + "Has Stopped: " + agent.isStopped);
if (Vector3.Distance(transform.position, agent.destination) < 3)
{
return true;
}
else
{
return false;
}
}
it seems to only slow the Gameobject down not actually stopping? What is the problem?
Answer by Toadill9114 · Aug 13, 2018 at 03:32 AM
[Citation][1] [1]: https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent-isStopped.html
public bool isStopped;
This property holds the stop or resume condition of the NavMesh agent.
If set to True, the NavMesh agent's movement will be stopped along its current path. If set to False after the NavMesh agent has stopped, it will resume moving along its current path.
So this would be good for stopping a AI along its path and then later resume to the path set already.
Instead of using isStopped try using remainingDistance
bool hasReachedDestination()
{
if (agent.remainingDistance == 0f)
return true;
else
return false;
}
This is very useful as well for an offset so that you are not trying to go on top of the object you clicked on.
bool hasReachedDestination()
{
agent.stoppingDistance = 2f; //<---Offset
if (agent.remainingDistance <= 2f)
return true;
else
return false;
}