Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Detecting if a target is off the navmesh?

Discussion in 'Navigation' started by EnsurdFrndship, Jun 2, 2015.

  1. EnsurdFrndship

    EnsurdFrndship

    Joined:
    Apr 17, 2010
    Posts:
    786
    Hello,
    How can I detect if a target is off the Navmesh using an if statement? Thank you.
     
  2. MysterySoftware

    MysterySoftware

    Joined:
    Sep 18, 2014
    Posts:
    46
    You could try something along those lines...

    Code (CSharp):
    1. NavMeshPath navpath = new NavMeshPath();
    2.  
    3. NavMesh.CalculatePath (somePosition, someOtherPosition, -1, navpath);
    4.  
    5. if (navpath.status == NavMeshPathStatus.PathPartial || navpath.status == NavMeshPathStatus.PathInvalid) {
    6.     // Not reachable
    7. }
     
  3. basil4j

    basil4j

    Joined:
    Sep 13, 2013
    Posts:
    1
    Dustin-Horne likes this.