|
@@ -13,7 +13,7 @@ Hence it is entirely possible (if not a little cumbersome) to exclusively use th
|
|
|
Communicating with the NavigationServer
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
-To work with the NavigationServer means to prepare parameters for a ``query`` that can be send to the NavigationServer for updates or requesting data.
|
|
|
+To work with the NavigationServer means to prepare parameters for a **query** that can be send to the NavigationServer for updates or requesting data.
|
|
|
|
|
|
To reference the internal NavigationServer objects like maps, regions and agents RIDs are used as identification numbers.
|
|
|
Every navigation related node in the scene tree has a function that returns the RID for this node.
|
|
@@ -22,19 +22,19 @@ Threading and Synchronization
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
The NavigationServer does not update every change immediately but waits until
|
|
|
-the end of the ``physics_frame`` to synchronize all the changes together.
|
|
|
+the end of the **physics frame** to synchronize all the changes together.
|
|
|
|
|
|
Waiting for synchronization is required to apply changes to all maps, regions and agents.
|
|
|
Synchronization is done because some updates like a recalculation of the entire navigation map are very expensive and require updated data from all other objects.
|
|
|
-Also the NavigationServer uses a ``threadpool`` by default for some functionality like avoidance calculation between agents.
|
|
|
+Also the NavigationServer uses a **threadpool** by default for some functionality like avoidance calculation between agents.
|
|
|
|
|
|
Waiting is not required for most ``get()`` functions that only request data from the NavigationServer without making changes.
|
|
|
Note that not all data will account for changes made in the same frame.
|
|
|
-E.g. if an avoidance ``agent`` changed the navigation ``map`` this frame the ``agent_get_map()`` function will still return the old map before the synchronization.
|
|
|
+E.g. if an avoidance agent changed the navigation map this frame the ``agent_get_map()`` function will still return the old map before the synchronization.
|
|
|
The exception to this are nodes that store their values internally before sending the update to the NavigationServer.
|
|
|
When a getter on a node is used for a value that was updated in the same frame it will return the already updated value stored on the node.
|
|
|
|
|
|
-The NavigationServer is ``thread-safe`` as it places all API calls that want to make changes in a queue to be executed in the synchronization phase.
|
|
|
+The NavigationServer is **thread-safe** as it places all API calls that want to make changes in a queue to be executed in the synchronization phase.
|
|
|
Synchronization for the NavigationServer happens in the middle of the physics frame after scene input from scripts and nodes are all done.
|
|
|
|
|
|
.. note::
|
|
@@ -43,28 +43,28 @@ Synchronization for the NavigationServer happens in the middle of the physics fr
|
|
|
|
|
|
The following functions will be executed in the synchronization phase only:
|
|
|
|
|
|
-- map_set_active()
|
|
|
-- map_set_up()
|
|
|
-- map_set_cell_size()
|
|
|
-- map_set_edge_connection_margin()
|
|
|
-- region_set_map()
|
|
|
-- region_set_transform()
|
|
|
-- region_set_enter_cost()
|
|
|
-- region_set_travel_cost()
|
|
|
-- region_set_navigation_layers()
|
|
|
-- region_set_navigation_mesh()
|
|
|
-- agent_set_map()
|
|
|
-- agent_set_neighbor_dist()
|
|
|
-- agent_set_max_neighbors()
|
|
|
-- agent_set_time_horizon()
|
|
|
-- agent_set_radius()
|
|
|
-- agent_set_max_speed()
|
|
|
-- agent_set_velocity()
|
|
|
-- agent_set_target_velocity()
|
|
|
-- agent_set_position()
|
|
|
-- agent_set_ignore_y()
|
|
|
-- agent_set_callback()
|
|
|
-- free()
|
|
|
+- ``map_set_active()``
|
|
|
+- ``map_set_up()``
|
|
|
+- ``map_set_cell_size()``
|
|
|
+- ``map_set_edge_connection_margin()``
|
|
|
+- ``region_set_map()``
|
|
|
+- ``region_set_transform()``
|
|
|
+- ``region_set_enter_cost()``
|
|
|
+- ``region_set_travel_cost()``
|
|
|
+- ``region_set_navigation_layers()``
|
|
|
+- ``region_set_navigation_mesh()``
|
|
|
+- ``agent_set_map()``
|
|
|
+- ``agent_set_neighbor_dist()``
|
|
|
+- ``agent_set_max_neighbors()``
|
|
|
+- ``agent_set_time_horizon()``
|
|
|
+- ``agent_set_radius()``
|
|
|
+- ``agent_set_max_speed()``
|
|
|
+- ``agent_set_velocity()``
|
|
|
+- ``agent_set_target_velocity()``
|
|
|
+- ``agent_set_position()``
|
|
|
+- ``agent_set_ignore_y()``
|
|
|
+- ``agent_set_callback()``
|
|
|
+- ``free()``
|
|
|
|
|
|
2D and 3D NavigationServer differences
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
@@ -73,11 +73,11 @@ NavigationServer2D and NavigationServer3D are equivalent in functionality
|
|
|
for their dimension and both use the same NavigationServer behind the scene.
|
|
|
|
|
|
Strictly technical a NavigationServer2D is a myth.
|
|
|
-The NavigationServer2D is a frontend to facilitate conversions of Vector2(x, y) to
|
|
|
-Vector3(x, 0.0, z) and back for the NavigationServer3D API. 2D uses a flat 3D mesh
|
|
|
+The NavigationServer2D is a frontend to facilitate conversions of ``Vector2(x, y)`` to
|
|
|
+``Vector3(x, 0.0, z)`` and back for the NavigationServer3D API. 2D uses a flat 3D mesh
|
|
|
pathfinding and the NavigationServer2D facilitates the conversions.
|
|
|
When a guide uses just NavigationServer without the 2D or 3D suffix it usually works for both servers
|
|
|
-by exchange Vector2(x, y) with Vector3(x, 0.0, z) or reverse.
|
|
|
+by exchange ``Vector2(x, y)`` with ``Vector3(x, 0.0, z)`` or reverse.
|
|
|
|
|
|
Technically it is possible to use the tools for creating navigation meshes in one dimension for the other
|
|
|
dimension, e.g. baking a 2D navigation mesh with the 3D NavigationMesh when using
|
|
@@ -105,11 +105,11 @@ At the start of the game, a new scene or procedural navigation changes any path
|
|
|
The navigation map is still empty or not updated at this point.
|
|
|
All nodes from the scene tree need to first upload their navigation related data to the NavigationServer.
|
|
|
Each added or changed map, region or agent need to be registered with the NavigationServer.
|
|
|
-Afterward the NavigationServer requires a ``physics_frame`` for synchronization to update the maps, regions and agents.
|
|
|
+Afterward the NavigationServer requires a **physics frame** for synchronization to update the maps, regions and agents.
|
|
|
|
|
|
One workaround is to make a deferred call to a custom setup function (so all nodes are ready).
|
|
|
The setup function makes all the navigation changes, e.g. adding procedural stuff.
|
|
|
-Afterwards the function waits for the next physics_frame before continuing with path queries.
|
|
|
+Afterwards the function waits for the next physics frame before continuing with path queries.
|
|
|
|
|
|
.. tabs::
|
|
|
.. code-tab:: gdscript GDScript
|
|
@@ -167,22 +167,22 @@ Server Avoidance Callbacks
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
If RVO avoidance agents are registered for avoidance callbacks the NavigationServer dispatches
|
|
|
-their ``safe_velocity`` signals just before the PhysicsServer synchronization.
|
|
|
+their ``velocity_computed`` signals just before the PhysicsServer synchronization.
|
|
|
|
|
|
To learn more about NavigationAgents see :ref:`doc_navigation_using_navigationagents`.
|
|
|
|
|
|
The simplified order of execution for NavigationAgents that use avoidance:
|
|
|
|
|
|
- physics frame starts.
|
|
|
-- _physics_process(delta).
|
|
|
-- set_velocity() on NavigationAgent Node.
|
|
|
+- ``_physics_process(delta)``.
|
|
|
+- ``set_velocity()`` on NavigationAgent Node.
|
|
|
- Agent sends velocity and position to NavigationServer.
|
|
|
- NavigationServer waits for synchronization.
|
|
|
- NavigationServer synchronizes and computes avoidance velocities for all registered avoidance agents.
|
|
|
-- NavigationServer sends safe_velocity vector with signals for each registered avoidance agents.
|
|
|
-- Agents receive the signal and move their parent e.g. with move_and_slide or linear_velocity.
|
|
|
+- NavigationServer sends safe velocity vector with signals for each registered avoidance agents.
|
|
|
+- Agents receive the signal and move their parent e.g. with ``move_and_slide`` or ``linear_velocity``.
|
|
|
- PhysicsServer synchronizes.
|
|
|
- physics frame ends.
|
|
|
|
|
|
-Therefore moving a physicsbody actor in the callback function with the safe_velocity is perfectly thread- and physics-safe
|
|
|
-as all happens inside the same physics_frame before the PhysicsServer commits to changes and does its own calculations.
|
|
|
+Therefore moving a physicsbody actor in the callback function with the safe velocity is perfectly thread- and physics-safe
|
|
|
+as all happens inside the same physics frame before the PhysicsServer commits to changes and does its own calculations.
|