Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NavMeshAgent.destination partialpath and actual progress of Agent along current path

Discussion in 'Editor & General Support' started by Jean-Fabre, Jan 5, 2012.

  1. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    429
    Hi,

    Moved from UnityAnswer to a thread cause I think this need to be discussed more than answered :)

    Ok, if destination is outside the navMesh, NavMeshDestination.destination even if path is partial keeps going down to 0 tho the Agent isn't , because blocked by the NavMesh Limits.

    So apparently this is suppoed to be that way:
    http://answers.unity3d.com/answers/202099

    But then how can I properly detect that an agent actually arrived and that the path has been completed indeed? This actually also applied when several agents are fighting for the same destination actually.

    Is it something that needs to be implemented manually like checking the distance between the agent and the destination? but that's not very accurate since the linear distance is certainly very different from the actual remaining path to be followed by the agent. Also Since the destination given can differ because of the navMesh mapping occuring.

    Also, what is the difference between using NavMeshAgent.destination and NavMeshAgent.SetDestination() ??

    Thanks for your help,

    Jean
     
  2. YorickVanVliet

    YorickVanVliet

    Joined:
    Nov 14, 2009
    Posts:
    22
    I'd also like to know how we can detect if the agent has arrived yet.

    *Edit:
    Just checking the RemainingDistance for 0 works. Its a little bit lame, i'd rather see a 'Arrived' bool, but this works.

    Code (csharp):
    1.  
    2.         while (!navAgent.pathPending  !Mathf.Approximately(0, navAgent.remainingDistance))
    3.             yield return new WaitForEndOfFrame();
    4.  
    I'm not sure the pathPending check is entirely necessary, but you can never be too sure ;)
     
    Last edited: Mar 16, 2012