|
@@ -1,25 +1,29 @@
|
|
|
.. _doc_navigation_using_navigationmeshes:
|
|
|
|
|
|
-Using NavigationMeshes
|
|
|
-======================
|
|
|
+Using navigation meshes
|
|
|
+=======================
|
|
|
|
|
|
-2D and 3D version of the navigation mesh are available as
|
|
|
+2D and 3D versions of the navigation mesh are available as
|
|
|
:ref:`NavigationPolygon<class_NavigationPolygon>` and
|
|
|
:ref:`NavigationMesh<class_NavigationMesh>` respectively.
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
- A navigation mesh describes the traversable safe area for an agent with its center position at zero radius.
|
|
|
+ A navigation mesh only describes a traversable area for an agent's center position. Any radius values an agent may have are ignored.
|
|
|
If you want pathfinding to account for an agent's (collision) size you need to shrink the navigation mesh accordingly.
|
|
|
|
|
|
-Navigation works independent from other engine parts like rendering and physics. A navigation mesh is the data format to exchange information from those other systems as it describes the traversable safe area for a specific agent. All the necessary information from other engine parts need to be already factored in when creating a navigation mesh. E.g. like visuals that an agent should not clip through or physics collision shapes that an agent should not collide with. This process of factoring in all those wanted navigation restrictions from other engine parts like visuals and collision is commonly called navigation mesh baking.
|
|
|
+Navigation works independently from other engine parts like rendering or physics.
|
|
|
+Navigation meshes are the only things considered when doing pathfinding, e.g. visuals and collision shapes for example are completely ignored by the navigation system.
|
|
|
+If you need to take other data (like visuals for example) into account when doing pathfinding, you need to adapt your navigation meshes accordingly.
|
|
|
+The process of factoring in navigation restrictions in navigation meshes is commonly referred to as navigation mesh baking.
|
|
|
|
|
|
-If you experience clipping or collision problems while following navigation paths always remember that you need to tell the navigation system through an appropriated navigation mesh what your intentions are. By itself the navigation system will never know "this is a tree / rock / wall collision shape or visual mesh" because it only knows "here I was told I can path safely cause it is on navigation mesh".
|
|
|
+If you experience clipping or collision problems while following navigation paths, always remember that you need to tell the navigation system what your intentions are through an appropriate navigation mesh.
|
|
|
+By itself the navigation system will never know "this is a tree / rock / wall collision shape or visual mesh" because it only knows that "here I was told I can path safely because it is on a navigation mesh".
|
|
|
|
|
|
.. _doc_navigation_navmesh_baking:
|
|
|
|
|
|
-Creating 2D NavigationMeshes
|
|
|
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
+Creating 2D navigation meshes
|
|
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
Navigation meshes in the 2D editor are created with the help of the NavigationPolygon draw tools
|
|
|
that appear in the top bar of the editor when a NavigationRegion2D is selected.
|
|
@@ -27,13 +31,13 @@ that appear in the top bar of the editor when a NavigationRegion2D is selected.
|
|
|
.. image:: img/nav_polydrawtool.png
|
|
|
|
|
|
The NavigationPolygon draw tools can be used to create and edit navigation meshes by defining ``outline`` polygons.
|
|
|
-The outline polygons are later converted to real NavigationMesh resources for the NavigationServer regions.
|
|
|
+The outline polygons are later converted to real navigation mesh resources for the NavigationServer regions.
|
|
|
|
|
|
.. image:: img/nav_polymatroschka.png
|
|
|
|
|
|
-Multiple outlines can be added to the same NavPolygon resource as long as they **do not intersect or overlap**.
|
|
|
+Multiple outlines can be added to the same NavigationPolygon resource as long as they **do not intersect or overlap**.
|
|
|
Each additional outline will cut a hole in the polygon created by the larger outline.
|
|
|
-If the larger polygon is already a hole it will create a new navigation mesh polygon inside.
|
|
|
+If the larger polygon is already a hole, it will create a new navigation mesh polygon inside.
|
|
|
|
|
|
Outlines are not a replacement if the intention is to merge aligned polygons e.g. from grid cells.
|
|
|
Outlines, as the name would suggest, cannot intersect each other or have any overlapping vertex positions.
|
|
@@ -41,20 +45,18 @@ Outlines, as the name would suggest, cannot intersect each other or have any ove
|
|
|
.. image:: img/nav_polyoutlinefail.png
|
|
|
|
|
|
Outline layouts like seen in this picture will fail the convex partitioning required by the navigation mesh generation.
|
|
|
-In this layout cases the outline tool cannot be used. Use the :ref:`Geometry2D<class_Geometry2D>` class for
|
|
|
-polygon merge or intersect operations to create a valid merged mesh for navigation.
|
|
|
+In these layout cases, the outline tool cannot be used. Use the :ref:`Geometry2D<class_Geometry2D>` class to merge or intersect polygons to create a merged mesh that is valid for navigation.
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
- The NavigationServer does not connect navigation mesh islands from the same NavigationMesh resource.
|
|
|
- Do not create multiple disconnected islands in the same NavigationRegion2D and NavPoly resource if they should be later connected.
|
|
|
+ The NavigationServer does not connect navigation mesh islands from the same navigation mesh resource.
|
|
|
+ Do not create multiple disconnected islands in the same NavigationRegion2D or NavigationPolygon resource if they should be later connected.
|
|
|
|
|
|
-For 2D no similar navigation mesh baking with geometry parsing exists like in 3D.
|
|
|
-The Geometry2D class functions for offset, merge, intersect and clip can be used
|
|
|
-to shrink or enlarge existing NavigationPolygons to different actor sizes.
|
|
|
+For 2D, no similar navigation mesh baking with geometry parsing exists like in 3D.
|
|
|
+The Geometry2D class functions for offset, merge, intersect, and clip can be used to shrink or enlarge existing NavigationPolygons for different actor sizes.
|
|
|
|
|
|
-Creating 3D NavigationMeshes
|
|
|
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
+Creating 3D navigation meshes
|
|
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
.. image:: img/baked_navmesh.png
|
|
|
|
|
@@ -62,12 +64,12 @@ Navigation meshes in the 3D editor are created with the help of the
|
|
|
:ref:`NavigationMeshGenerator<class_NavigationMeshGenerator>` singleton
|
|
|
and the NavigationMesh bake settings that appear in the editor inspector.
|
|
|
|
|
|
-NavigationMesh baking is the process of creating a simplified mesh used for pathfinding out of (complex) 3D level geometry.
|
|
|
+Navigation mesh baking is the process of creating a simplified mesh used for pathfinding out of (complex) 3D level geometry.
|
|
|
For this process Godot parses scene geometry and hands the raw mesh or collision data to the
|
|
|
-third-party ReCast library for processing and creation of the final navigationmesh.
|
|
|
+third-party ReCast library for processing and creation of the final navigation mesh.
|
|
|
|
|
|
-The resulting NavigationMesh is an approximation of the source geometry surfaces
|
|
|
-for both performance and technical reasons. Do not expect the NavigationMesh
|
|
|
+The resulting navigation mesh is an approximation of the source geometry surfaces
|
|
|
+for both performance and technical reasons. Do not expect the navigation mesh
|
|
|
to perfectly follow the original surfaces. Especially navigation polygons placed
|
|
|
over ramps will not keep an equal distance to the ground surface. To align an
|
|
|
actor perfectly with the ground use other means like physics.
|
|
@@ -79,9 +81,9 @@ actor perfectly with the ground use other means like physics.
|
|
|
NavigationMesh rebaking at runtime
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
-To rebake a ``NavigationMesh`` at runtime, use the NavigationRegion3D.bake_navigation_mesh() function.
|
|
|
-Another option is to use the NavigationMeshGenerator.bake() Singleton function with the NavigationMesh resource directly.
|
|
|
-If the navigation mesh resource is already prepared, the region can be updated with the NavigationServer3D API directly as well.
|
|
|
+To rebake a ``NavigationMesh`` at runtime, use the ``NavigationRegion3D.bake_navigation_mesh()`` function.
|
|
|
+Another option is to use the ``NavigationMeshGenerator.bake()`` singleton function with the NavigationMesh resource directly.
|
|
|
+If the NavigationMesh resource is already prepared, the region can be updated with the NavigationServer3D API directly as well.
|
|
|
|
|
|
.. tabs::
|
|
|
.. code-tab:: gdscript GDScript
|
|
@@ -94,7 +96,7 @@ If the navigation mesh resource is already prepared, the region can be updated w
|
|
|
var on_thread: bool = true
|
|
|
bake_navigation_mesh(on_thread)
|
|
|
|
|
|
- # or use the NavigationMeshGenerator Singleton
|
|
|
+ # or use the NavigationMeshGenerator singleton
|
|
|
var _navigationmesh: NavigationMesh = navigation_mesh
|
|
|
NavigationMeshGenerator.bake(_navigationmesh, self)
|
|
|
# remove old resource first to trigger a full update
|
|
@@ -108,7 +110,7 @@ If the navigation mesh resource is already prepared, the region can be updated w
|
|
|
.. note::
|
|
|
|
|
|
Baking a NavigationMesh at runtime is a costly operation.
|
|
|
- Complex navigation mesh take some time to bake and if done on the main thread can freeze a game.
|
|
|
+ A complex navigation mesh takes some time to bake and if done on the main thread can freeze a game.
|
|
|
(Re)baking a large navigation mesh is preferably done in a separate thread.
|
|
|
|
|
|
.. warning::
|
|
@@ -117,23 +119,23 @@ If the navigation mesh resource is already prepared, the region can be updated w
|
|
|
to match the actual mesh data stored inside in order to merge
|
|
|
different navigation meshes without issues.
|
|
|
|
|
|
-NavigationRegion2D and Navigation3D both use meshes to mark traversable areas, only the tools to create them are different.
|
|
|
+NavigationRegion2D and NavigationRegion3D both use meshes to mark traversable areas, only the tools to create them are different.
|
|
|
|
|
|
-For 2D NavigationPolygon resources are used to draw outline points in the editor. From these outline points the NavigationServer2D creates a mesh to upload navigation data to the NavigationServer.
|
|
|
+For 2D, NavigationPolygon resources are used to draw outline points in the editor. From these outline points the NavigationServer2D creates a mesh to upload navigation data to the NavigationServer.
|
|
|
|
|
|
-For 3D NavigationMesh resources are used. Instead of providing draw tools the 3D variant
|
|
|
+For 3D, NavigationMesh resources are used. Instead of providing draw tools the 3D variant
|
|
|
provides an extensive amount of parameters to bake a navigation mesh directly from 3D source geometry.
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
- Technically there is no hard distinction between 2D and 3D how to use the given toolsets to create flat navigation meshes. The 2D drawing tool can be used to create a flat 3D navmesh and the 3D baking tool can be used to parse flat 3D geometry into 2D appropriated navigationmeshes.
|
|
|
+ Technically there is no hard distinction between 2D and 3D on how to use the given toolsets to create flat navigation meshes. The 2D drawing tool can be used to create a flat 3D navigation mesh and the 3D baking tool can be used to parse flat 3D geometry into appropriate 2D navigation meshes.
|
|
|
|
|
|
-2D Navmesh from CollisionPolygons
|
|
|
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
+2D navigation mesh from CollisionPolygons
|
|
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
The following script parses all child nodes of a NavigationRegion2D for CollisionPolygons
|
|
|
and bakes their shape into the NavigationPolygon. As the NavigationPolygon creates the
|
|
|
-navigationmesh from outline data the shapes cannot overlap.
|
|
|
+navigation mesh from outline data the shapes cannot overlap.
|
|
|
|
|
|
.. tabs::
|
|
|
.. code-tab:: gdscript GDScript
|
|
@@ -165,10 +167,10 @@ navigationmesh from outline data the shapes cannot overlap.
|
|
|
|
|
|
new_navigation_polygon.add_outline(new_collision_outline)
|
|
|
|
|
|
-Procedual 2D NavigationMesh
|
|
|
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
+Procedural 2D navigation mesh
|
|
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
-The following script creates a new 2D navigation region and fills it with procedual generated navigation mesh data from a NavigationPolygon resource.
|
|
|
+The following script creates a new 2D navigation region and fills it with procedurally generated navigation mesh data from a NavigationPolygon resource.
|
|
|
|
|
|
.. tabs::
|
|
|
.. code-tab:: gdscript GDScript
|
|
@@ -192,10 +194,10 @@ The following script creates a new 2D navigation region and fills it with proced
|
|
|
|
|
|
NavigationServer2D.region_set_navigation_polygon(new_2d_region_rid, new_navigation_polygon)
|
|
|
|
|
|
-Procedual 3D NavigationMesh
|
|
|
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
+Procedural 3D navigation mesh
|
|
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
-The following script creates a new 3D navigation region and fills it with procedual generated navigation mesh data from a NavigationMesh resource.
|
|
|
+The following script creates a new 3D navigation region and fills it with procedurally generated navigation mesh data from a NavigationMesh resource.
|
|
|
|
|
|
.. tabs::
|
|
|
.. code-tab:: gdscript GDScript
|
|
@@ -220,10 +222,10 @@ The following script creates a new 3D navigation region and fills it with proced
|
|
|
)
|
|
|
NavigationServer3D.region_set_navigation_mesh(new_3d_region_rid, new_navigation_mesh)
|
|
|
|
|
|
-Navmesh for 3D GridMaps
|
|
|
-~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
+Navigation mesh for 3D GridMaps
|
|
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
-The following script creates a new 3D navigation mesh for each GridMap items, clears the current grid cells and adds new procedual grid cells with the new navigation mesh.
|
|
|
+The following script creates a new 3D navigation mesh for each GridMap items, clears the current grid cells, and adds new procedural grid cells with the new navigation mesh.
|
|
|
|
|
|
.. tabs::
|
|
|
.. code-tab:: gdscript GDScript
|
|
@@ -254,7 +256,7 @@ The following script creates a new 3D navigation mesh for each GridMap items, cl
|
|
|
# clear the cells
|
|
|
clear()
|
|
|
|
|
|
- # add procedual cells using the first item
|
|
|
+ # add procedural cells using the first item
|
|
|
var _position: Vector3i = Vector3i(global_transform.origin)
|
|
|
var _item: int = 0
|
|
|
var _orientation: int = 0
|