Creating a movable NavMesh Obstacle
Sometimes, we want a moving object to slow down or prevent an AI NavMeshAgent
controlled character passing through an area of our game. Or, perhaps we want something like a door or drawbridge to sometimes permit travel, and not at other times. We can't "bake" these objects into the NavMesh
at Design-Time
, since we want to change them during Run-Time
.
While computationally more expensive (that is, they slow down your game more that static non-navigable objects), NavMesh Obstacles
are components that can be added to GameObjects, and these components can be enabled and disabled like any other component.
A special property of NavMesh Obstacles
is that they can be set to "carve out" areas of the NavMesh
, causing NavMeshAgents
to then recalculate routes that avoid these carved out parts of the mesh.
In this recipe, you'll create a player-controlled red Cube
, which you can move to obstruct an AI NavMeshAgent
controlled character. Also, if your cube stays in one...