Creating dynamic NavMeshes with obstacles
There are times when our levels have dynamic obstacles and we need the agent to avoid those obstacles as well. Let's imagine an MMORPG or a MOBA, where the minions from our hero also need to avoid obstacles in order to reach the target. We could implement a difficult algorithm to blend the navigation with the obstacle avoidance, or we could leverage the power of a dynamic NavMesh to get the same result, with little to no code disruption.
In this recipe, we will learn how to adapt a NavMesh to be dynamic and react to moving obstacles, so our agents can avoid them and reach the target successfully.
Getting ready
It is important to know how the NavMesh basics work, and how to build/bake a NavMesh.
How to do it...
- Put the level in place.
- Create an empty game object and call it
NavMesh
. - Add the
NavMeshSurface
component to theNavMesh
object. - Hit
Bake
. - Select all the obstacles.
- Add the
Nav Mesh Obstacle
component to them. - Check the
Carve
option in the component...