Search Unity

[SOLVED] Check if destination is inside NavMeshObstacle

Discussion in 'Navigation' started by Inferi, Apr 29, 2018.

  1. Inferi

    Inferi

    Joined:
    Sep 28, 2015
    Posts:
    145
    Is there a way to check if a destination is inside a NavMeshObstacle?

    I am using this code today to calculate path:

    Code (CSharp):
    1.     public bool CalculateTheAgentPath() {
    2.         if (this.agent != null) { // If agent exist
    3.             if (this.agent.isOnNavMesh) {
    4.                 bool hasFoundPath = this.agent.CalculatePath(currentTarget.position, path);
    5.                 if (this.path.status == NavMeshPathStatus.PathComplete) {
    6.                     Debug.Log("The agent can reach the destionation");
    7.                     return true;
    8.                 } else if (this.path.status == NavMeshPathStatus.PathPartial) {
    9.                     Debug.Log("The agent can only get close to the destination");
    10.                     return true;
    11.                 } else if (this.path.status == NavMeshPathStatus.PathInvalid) {
    12.                     Debug.Log("Path invalid");
    13.                     return false;
    14.                 }
    15.             }
    16.         }
    17.         return false;
    18.     }
    19.  
    The only response I get when player is inside a obstacle is "The agent can reach the destionation", just if the path was complete. The enemy is walking around the obstacle so I would say that the path is not complete?.

    I would like the enemy to ignore player if inside an obstacle.


    Anyway to do this?
     
  2. Inferi

    Inferi

    Joined:
    Sep 28, 2015
    Posts:
    145
    Ok, so I solved it with the help of triggers and a Static variable that is set to true if player is inside a collider "that also is a NavMeshObstacle. I dont know if this is the correct way of doing things, but it works.

    I will leave this thread unsolved for some days and if anyone has a better solution, feel free to add your ideas. :)
     
    DungDajHjep likes this.