- Home /
How do I get NavMeshAgents not to walk through objects?
Hey, everyone! This is my first question on the Unity Forums!
So, I have a NavMeshAgent attached to a player-controlled unit. When the player clicks a valid target, the unit moves towards that target on the NavMesh. However, if I try to give it a target on the other side of an obstacle, the agent just goes right through it! I've messed with colliders, rigidbodies, and isKinematic, but to no avail.
[1]: http://answers.unity3d.com/questions/659652/navmeshagent-collision.html
Answer by servival · Feb 02, 2016 at 11:36 AM
You need to add a nav mesh obstacle component to your non-static objects.
Sorry to be stupid, does that mean adding the nav mesh obstacle to each "character" or moving unit, as opposed to every "house" or stationary object?
What this means is, if you have an object (say, a house) that should block movement of an agent (say, your player character), AND that object could possibly move or be destroyed, then you add the Nav$$anonymous$$eshObstacle component to that object. This is because any obstacles that DON'T move or get destroyed should be marked as static so the navmesh is baked with them in $$anonymous$$d. If such an object were destroyed, the navmesh still contains a "hole" that the player could not traverse, because the navmesh doesn't get recalculated at runtime. As Danteswap mentions below, you'll want the "carve" option checked.
Nav$$anonymous$$esh obstacles can't pass through walls which can be a problem when making sliding doors
Answer by Nanofication · Feb 02, 2016 at 05:32 PM
For your obstacle, try
1) Going to navigation tab
2) Go to the object tab of the navigation tab
3) Select Navigation Static
4) Go to Navigation Area change Walkable to Not Walkable
5) Click Bake (Rebake the NavMesh)
This just makes them permanently impassable. I want units to be able to walk through where they were once the objects are destroyed. Thanks though!
Ah I see, sorry about that.
@servival 's answer does satisfy your issue then.
Answer by danteswap · Nov 14, 2017 at 10:51 PM
On The Obstacle Add NavMesh Obstacle Component Now Choose Desired Shape For Obstacle , I would Suggest To use Box , Now Adjust The Size So That the It Covers Your Obstacle Object , For Now To Test Just Use Value Of 2 In all X,Y,Z And Enable The Carve Option . Now In The Scene You Can Try To Move Your Obstacle And You Will See The NavMesh Around The Obstacle Gets Modified . Now Play the Scene And Give Target to Your Player And in Scene View bring The Obstacle In front Of Player . now It Will Not Go Through The Obstacle but Will Find New Path . Again For Fun You can Move Obstacle In front Of Player And Player Will Find New Way to Reach The Target . have Fun
Your answer
Follow this Question
Related Questions
Enemies using navmesh are bumping each other through solid objects 1 Answer
Navmesh y-axis 1 Answer
Navmesh agent got fused in very crowded situation when colliding. 0 Answers
How to have a navmeshagent not move rigidbodies in my world? 0 Answers
What is the difference between configuration of agent in 'Agents' tab and in 'Bake' tab Unity? 1 Answer