Real Time Navigation (3D)¶
Setting up navigation¶
To add navigation to a scene you need to add a navigation node, then a navigation mesh instance as a child of the navigation node. With the navigation mesh instance selected you need to go to the inspector and create a new navigation mesh.
Click on the navigation mesh and you can now alter the properties that define how the navigation mesh is generated. You can find a full description for each of the properties in the class reference here: NavigationMesh.
After making the changes you want the mesh can be generated by clicking Bake NavMesh in the toolbar.
Once the mesh has finished generating you should see the transparent navigation mesh above the areas in your scene that can be navigated to.
Keep in mind that the navmesh shows where the center of an entity can go. For example, if you set the agent radius to 0.5 then your navigation mesh will have a distance of 0.5 from any ledges or walls to prevent clipping into the wall or hanging off of the edge.
Generating a path¶
To get a path between two areas on a map you use the navigation node
get_simple_path(). The first argument is a Vector3 of the
starting location, the next is a Vector3 of the end location. And the
last argument is a boolean for whether or not agent properties of a
navmesh are considered when generating a path.
Official example project¶
There is an official example project on how to use 3D navigation. You can find the repository here. It can also be found in the asset library.