[SOLVED] Check if destination is inside NavMeshObstacle

Is there a way to check if a destination is inside a NavMeshObstacle?

I am using this code today to calculate path:

    public bool CalculateTheAgentPath() {
        if (this.agent != null) { // If agent exist
            if (this.agent.isOnNavMesh) {
                bool hasFoundPath = this.agent.CalculatePath(currentTarget.position, path);
                if (this.path.status == NavMeshPathStatus.PathComplete) {
                    Debug.Log("The agent can reach the destionation");
                    return true;
                } else if (this.path.status == NavMeshPathStatus.PathPartial) {
                    Debug.Log("The agent can only get close to the destination");
                    return true;
                } else if (this.path.status == NavMeshPathStatus.PathInvalid) {
                    Debug.Log("Path invalid");
                    return false;
                }
            }
        }
        return false;
    }

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?

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. :slight_smile:

1 Like