Pathfinding and obstacle detection with navMesh
NavMesh is Unity's pathfinding system. It works by defining the navigable areas of the game level, storing this as a simple mesh. Once areas that can be accessed are defined, the navMesh is baked like a lightmap.
This system offers numerous advantages over waypoint systems. Firstly, it allows an AI character to roam freely within a level.
Open the scene
Chapter9_nav_Start
.The scene contains the office environment with a navMesh already baked. The steps taken to set this up are well documented on the Unity website.
We can view the generated navMesh by activating the Navigation panel.
From the menu bar, choose Window | Navigation.
The Navmesh Display box will appear in the lower right of the Scene view.
By default, the Show NavMesh checkbox should be checked and the walkable areas of the game level will be displayed in blue:
In the scene, the patrol points have been placed to make a more complex route for the zombie. If you press the Play button at...