Search Unity

Agent stops before stopping distance

Discussion in 'Navigation' started by douglassophies, Jul 2, 2020.

  1. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
    I have code that checked if i was within stopping distance. If not then set the new destination, else call an event to say i have reached it.
    Like this:
    Code (CSharp):
    1. if(Vector3.Distance(transform.position, target.transform.position) >  agent.stoppingDistance)
    2. {
    3. agent.SetDestination(target.transform.position)
    4. }
    5. else DestinationRechedEvent.Invoke();
    It worked well. Sometimes the agent would get a bit closer but that was expected and accounted for based on my understanding of the behavior. But i have now noticed it sometimes stops before the stopping distance. So the SetDestination code does not make it move but it has not reached it yet. Its only of by a few decimal places and i can account for it by rounding but I wonder if there is something im doing wrong that i can fix rather than inserting rounding code all over. (I use it in a few different forms a lot)