RidgetBuddy
RidgetBuddy

Reputation: 11

Unity Navmesh destroy Obstacle

I have a basic NavMesh setup in Unity. A plane, an Agent and a destination. So far, my Agent follows the path to its destination.

When i Place an obstacle in its way, it will stop at the obstacle.

Is there a way to tell the Agent (or the obstacle?) to be destroyed, when the Path is completely blocked?

When the Agent can walk around the obstacle, I am fine with that. But a complete block should lead to the destruction of the obstacle (destruction in the moment the agent "touches" the obstacle)

I hope you understand the problem.

Upvotes: 1

Views: 515

Answers (1)

Foggzie
Foggzie

Reputation: 9821

Whenever a new obstacle is created, you can use NavMeshAgent's CalculatePath method. Given a target position, it will return true and fill out the path parameter if a path is found; it will return false if a path isn't found. You can use the result of this method to determine whether or not your obstacle should be deleted.

Keep in mind there is a chance this method returns true but the path has a status field that could have the value NavMeshPathStatus.PathPartial. Because of this, you'll want to be sure you're checking both the return value of CalculatePath as well as the status value of the path.

Upvotes: 0

Related Questions