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?
- You have a surface where your GameObjects will navigate through.
- You have several GameObjects that are obstacles or “unwakable”.
- 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
- 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.
- Download NavMeshComponents and copy-paste it into your project.
- Create an empty Game Object and attach the NavMeshSurface component to it. Click Bake.
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.