2.3 KiB
2.3 KiB
Creating a NavMesh Obstacle
NavMesh Obstacle components can be used to describe obstacles the agents should avoid while navigating. For example the agents should avoid physics controlled objects, such as crates and barrels while moving.
We’re going to add a crate to block the pathway at the top of the level.
- First create a cube to depict the crate: Game Object > 3D Object > Cube.
- Move the cube to the platform at the top, the default size of the cube is good for a crate so leave it as it is.
- Add a NavMesh Obstacle component to the cube. Choose Add Component from the inspector and choose Navigation > NavMesh Obstacle.
- Set the shape of the obstacle to box, changing the shape will automatically fit the center and size to the render mesh.
- Add a Rigid body to the obstacle. Choose Add Component from the inspector and choose Physics > Rigid Body.
- Finally turn on the Carve setting from the NavMesh Obstacle inspector so that the agent knows to find a path around the obstacle.
Now we have a working crate that is physics controlled, and which the AI knows how to avoid while navigating.
Additional resources
- Inner Workings of the Navigation System - learn more about how obstacles are used as part of navigation.
- NavMesh Obstacle component reference – full description of all the NavMesh Obstacle properties.
- NavMesh Obstacle scripting reference - full description of the NavMesh Obstacle scripting API.