Unity’s NavMeshComponents Tutorial (3D)

NavMeshComponents is Unity’s latest solution to path-finding or sometimes also referred to as Navigation. Navigation means having a component in Unity that can find a path to a position. This position is often represented as a Vector3.

How does it work?

  1. You have a surface where your GameObjects will navigate through.
  2. You have several GameObjects that are obstacles or “unwakable”.
  3. You have a GameObject that is going to be navigating. This GameObject is also called an “Agent”.

Use NavMeshSurface to define a surface.

Use NavMeshModifier to add obstacles or “unwakable” GameObjects.

use NavMeshAgent to define the GameObject that can navigate through our surface.

Step by step

Tools:

  • Unity 2019.4.0f1
  • I created a simple 3D project in Unity. You can download all the Assets for this project here and follow along.
  1. Download NavMeshComponents and copy-paste it into your project.
  2. Create an empty Game Object and attach the NavMeshSurface component to it. Click Bake.
I like to create a Game Object called “NavMesh” and attach my NavMeshSurface component to it.

3. To create the Agent, create a primitive Capsule Game Object by going to “Game Object -> 3D Object -> Capsule”. I will name this Game Object “Agent”.

4. To make the Agent move we need the NavMeshAgent component provided by Unity and a script that can tell the NavMeshAgent that it needs to move. For this I have created a simple script called NavMeshAgentController.

5. The NavMeshAgentController has a variable “Target” that can be any game object. For this tutorial, I created another primitive Sphere and set that as the target.

That’s it. Hit play and move the sphere around the scene and you will see how the Agent follows the sphere.

Feel free to leave your feedback below or email me directly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s