- Home /
Is it possible to have a navmesh agent that ignores obstacles?
I am using navmesh agents to handle pathing for enemy units, but I've come upon a use case where I have certain units that I want to ignore obstacles in their path. (Ex: Massive unit can walk over and destroy buildings in its path). I saw this question and comment that says that the navmesh doesn't currently support it, but that was 3 years ago and I was hoping that this feature may have been implemented since then. If it hasn't, has anyone come up with a solution/work around to this?
Thanks!
Using Unity 5.4.0f3
Answer by juicyz · Sep 27, 2016 at 06:56 PM
I think you will want to look into: https://docs.unity3d.com/ScriptReference/NavMeshAgent-areaMask.html
Another solution is that you could also make a custom 'navigator'. Basically don't use NavMesh and just make the unit walk along a tangent line (straight at its target)
Hmm, I think the Area$$anonymous$$ask might work... I'll just have to define a mask for buildings and then each time a building is built apply that mask to that area of the mesh. $$anonymous$$ight also solve another one of my issues if I can just query the mesh to see if there is already something in the area that a new building would end up occupying. I'll accept the answer in a day or two after I've had time to implement this. Thanks for the advice!
Accepting as correct since this route (area$$anonymous$$ask) was the correct direction to take and will be for anyone looking for a way to do this statically. Unfortunately though, it turns out that you can't bake Nav$$anonymous$$eshes at runtime, so there's no way to make this feasible in my use case. Will need to implement my own system or drop this part of the game unfortunately.
What was your final solution? I'm trying to get two units to walk into each other using nav mesh agents but they also try to avoid each other at the same time.
This was just a small side project for me to "scratch an itch," and I ended up dropping it due to my work load at school and work. I am doing something similar to what you want in UE4 for a project for school that I'm working on right now though. $$anonymous$$y current solution is to disable obstacle avoidance when the attacker gets close enough to its target. It's been a while since I've used Unity's nav system now, but I want to say that you can achieve something similar in there. It may also be possible to calculate a path that just has to get within radius X of the target and then simple path (not relying on nav agent movement) after that. Best of luck to you!