- Home /
How to let a navMeshAgent detect if path is blocked by an obstacle?
How can I detect if a navMesh agent can reach a destination that is blocked by an Obstacle?
I have a level where it is already baked to a navMesh, I am using navMesh Obstacles as well. I need the obstacles to prevent the agents from going further in the path, when I give an agent a destination that's blocked by an obstacle the agent tries to reach it but it can't. I would like to let the agent detect that its current destination can't be reached so it doesn't even try.
Thanks
Not entirely sure but i think this can solve your issue.
Nav$$anonymous$$eshPath path = new Nav$$anonymous$$eshPath();
GetComponent<Nav$$anonymous$$eshAgent>().CalculatePath(destination, path);
if (path.status == Nav$$anonymous$$eshPathStatus.PathPartial)
{
//reset a path
}
I tried to use your solution in Unity 4 and it wasn't working for Obstacles, it always gave me PathComplete. But I just tried it now in Unity 5, it's working great. Thank you
Answer by xxxSMDxxx · May 09, 2017 at 05:20 AM
Have you tried the Carve property in the Nav Mesh Obstacle Component. Carve will destroy part of the navmesh where the obstacle is. But rebuild it when it's not there.
Hi, I don't mean to be rude, I really appreciate your help but did you read the question? Back then I was using Nav$$anonymous$$esh Obstacle already and the problem was that I wasn't able to know if a path is blocked by an obstacle or not. One comment showed me the solution. This is a pretty old question too.
Again I really appreciate your help and I'm sorry if I'm sounding rude :)