Working With Unity’s Navigation System
Unity’s Navigation system allows easy creation of AI agents that are able to move freely and accurately around the environment.
Today’s Objective: Set up Unity’s Navigation System to be ready for my point-and-click movement system.
Unity Navigation:
Unity has a very good built-in AI navigation system which is suitable for most game needs. It can be found by going to “Window/AI/Navigation”, which opens this window.
The system works using 2 main elements: The environment and the Nav Mesh Agents.
The environment can be any object in the scene marked as “Navigation Static”.
The Nav Mesh Agents are any object in the scene that you want to be an entity (player or NPC) with navigation capabilities. It needs to have the “Nav Mesh Agent” component added.
Baking the Nav-Mesh:
At some point, you will need to “bake” the navigation mesh to the scene. This is done by:
While the Navigation window is visible, a blue overlay will be shown on top of every object in the scene marked as Navigation Static. Any area with a blue overlay is “walkable” using the current navigation settings.
Creating a Nav Mesh Agent:
Create a new GameObject (For prototyping, I use a 3D Capsule):
Add a NavMeshAgent component to it.
All NavMesh Agents are automatically locked to the navigation mesh.
By setting the NavMeshAgent’s “destination” variable via the public method “SetDestination(Vector3 destination)”, you can make the Agent move towards the destination. The Agent automatically pathfinds around any objects/obstacles/walls in the nav mesh.