The NavMeshAgent component that we added to the Sphere-arrow GameObject does most of the work for us. NavMeshAgents need two things:
- A destination location to head toward
- A NavMesh component of the terrain with walkable/non-walkable areas so that it can plan a path by avoiding obstacles
We created two obstacles (the Cube-wall objects), and these were selected when we created the NavMesh for this scene in the Navigation window. When the Navigation window is displayed, at the same time in the Scene window (and the Game window with Gizmos enabled), we can see walkable areas forming a blue navigation mesh.
Note that the blue areas are the default NavMesh area. Later in this chapter, we'll look at different, custom named, costed, and color-coded NavMesh areas.
The location for our NPC object to travel toward is the position of the Capsule-destination GameObject at (-12, 0, 8); but, of course, we could just move this object in the Scene window...