I have a project where I am using NavMesh Agent and Obstacles as a core mechanics of the game. I have baked a NavMeshSurface to the ground so the Agents can find their way to the End point. The player is placing Obstacles in front of the Agents to block their path. I am struggling to make the Agents do damage to the Obstacles if they are fully blocked and there is no available path to the end point. Note: (By fully blocked I mean that they are just standing at one place and do nothing. If this happens I want the Agents to start attacking the Obstacles in order to make their own way to the End point) Any suggestions of how to check if there is available path are deeply appreciated! Thank you in advance
Asked
Active
Viewed 1,934 times
-1
-
what have you tried? what specifically is the question – BugFinder Aug 31 '20 at 16:01
1 Answers
1
Welcome to the community Svetoslav.
Doing quick search on NavMeshAgent check if endpoint is reachable yielded the answer right away (https://answers.unity.com/questions/1254520/how-to-check-if-agent-destination-can-be-reached.html (answer by Arcana96))
There's a method called CalculatePath which allows you check whether a position is reachable before you move the agent. Here's the documentation: https://docs.unity3d.com/ScriptReference/NavMeshAgent.CalculatePath.html
Using CalculatePath
method returns NavMeshPath
object. It can be used to check if endpoint is reachable (check the documentation). After getting positive results, you can set that path to NavMeshAgent
's path
property.

tsvedas
- 1,049
- 7
- 18
-
Thank you so much I have implemented it and now it is working fine! I am calling it in Update() as I want to check for the path continuously. Now I will need to make the Agent to attack the closest Obstacle. Thank you for your help! – Svetoslav Gyuretsov Aug 31 '20 at 16:28