Search Unity

Agent.stop when reach min distance, versus stopping distance on the navmesh agent

Discussion in 'Navigation' started by rapidrunner, Apr 24, 2016.

  1. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    When I script the agent, I set the destination, and then I check if the distance between the agent and the target is less than a value X, if it is, I set agent.stop.

    This is how the agent knows that it reach the destination point for its target, but then in the navmesh agent, there is a parameter called "stopping distance". Are they working in conjunction? Is one overriding the other? Because at times I see confusing behaviors.

    For example, if I change at runtime the stopping distance on the agent, nothing really change; and I do not understand exactly what "1" means, if I decide to calculate the distance between the agent and the target, using

    Code (CSharp):
    1. if (Vector3.Distance(transform.position, target.transform.position) >= 1)
    Because it is not 1 meter; I did try to create a cube, to use as unit of measure (1 cube=1 unit =1 meter, using standard Unity setup), and it was pretty far from the destination target, while the agent end up getting closer.

    Can someone please clarify how to correctly deal with stopping distance, between calculating the distance from the target, and using "stopping distance" in the navmesh agent? The fact that changing the stopping distance has no effect while in runtime look like a bug to me.