|
@@ -3,22 +3,22 @@
|
|
|
Using NavigationAgents
|
|
|
======================
|
|
|
|
|
|
-NavigationsAgents are helper nodes to facilitate common calls to the NavigationServer API
|
|
|
+NavigationsAgents are helper nodes to facilitate common calls to the NavigationServer API
|
|
|
on behalf of the parent actor node in a more convenient manner for beginners.
|
|
|
|
|
|
-2D and 3D version of NavigationAgents are available as
|
|
|
-:ref:`NavigationAgent2D<class_NavigationAgent2D>` and
|
|
|
+2D and 3D version of NavigationAgents are available as
|
|
|
+:ref:`NavigationAgent2D<class_NavigationAgent2D>` and
|
|
|
:ref:`NavigationAgent3D<class_NavigationAgent3D>` respectively.
|
|
|
|
|
|
-NavigationsAgents are entirely optional for navigation pathfinding.
|
|
|
-The functionality of NavigationsAgents can be recreated with scripts and direct
|
|
|
-calls to the NavigationServer API. If the default NavigationsAgent does not do what you want
|
|
|
+NavigationsAgents are entirely optional for navigation pathfinding.
|
|
|
+The functionality of NavigationsAgents can be recreated with scripts and direct
|
|
|
+calls to the NavigationServer API. If the default NavigationsAgent does not do what you want
|
|
|
for your game feel free to design your own NavigationsAgent with scripts.
|
|
|
|
|
|
.. warning::
|
|
|
|
|
|
- NavigationsAgent nodes and NavigationServer ``agents`` are not the same.
|
|
|
- The later is an RVO avoidance agent and solely used for avoidance.
|
|
|
+ NavigationsAgent nodes and NavigationServer ``agents`` are not the same.
|
|
|
+ The later is an RVO avoidance agent and solely used for avoidance.
|
|
|
RVO avoidance agents are not involved in regular pathfinding.
|
|
|
|
|
|
NavigationAgent Pathfinding
|
|
@@ -27,23 +27,23 @@ NavigationAgent Pathfinding
|
|
|
To use NavigationAgents for pathfinding, place a NavigationAgent2D/3D Node below a Node2D/3D inheriting parent node.
|
|
|
|
|
|
To have the agent query a path to a target position use the ``set_target_location()`` method.
|
|
|
-Once the target has been set, the next position to follow in the path
|
|
|
-can be retrieved with the ``get_next_location()`` function. Move the parent actor node
|
|
|
-to this position with your own movement code. On the next ``physics_frame``, call
|
|
|
+Once the target has been set, the next position to follow in the path
|
|
|
+can be retrieved with the ``get_next_location()`` function. Move the parent actor node
|
|
|
+to this position with your own movement code. On the next ``physics_frame``, call
|
|
|
``get_next_location()`` again for the next position and repeat this until the path ends.
|
|
|
|
|
|
NavigationAgents have their own internal logic to proceed with the current path and call for updates.
|
|
|
NavigationAgents recognize by distance when a path point or the final target is reached.
|
|
|
NavigationAgents refresh a path automatically when too far away from the current pathpoint.
|
|
|
-The important updates are all triggered with the ``get_next_location()`` function
|
|
|
+The important updates are all triggered with the ``get_next_location()`` function
|
|
|
when called in ``_physics_process()``.
|
|
|
|
|
|
-Be careful calling other NavigationAgent functions not required for path movement
|
|
|
+Be careful calling other NavigationAgent functions not required for path movement
|
|
|
while the actor is following a path, as many function trigger a full path refresh.
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
- New NavigationAgents will automatically join the
|
|
|
+ New NavigationAgents will automatically join the
|
|
|
default navigation map for their 2D/3D dimension.
|
|
|
|
|
|
.. warning::
|
|
@@ -68,8 +68,8 @@ They work well out of the box with :ref:`CharacterBody2D<class_CharacterBody2D>`
|
|
|
NavigationAgent Avoidance
|
|
|
-------------------------
|
|
|
|
|
|
-This section explains how to use the built-in avoidance specific
|
|
|
-to NavigationAgent nodes. For general avoidance use and more technical details
|
|
|
+This section explains how to use the built-in avoidance specific
|
|
|
+to NavigationAgent nodes. For general avoidance use and more technical details
|
|
|
on RVO avoidance see :ref:`doc_navigation_using_agent_avoidance`.
|
|
|
|
|
|
|
|
@@ -87,8 +87,8 @@ The following NavigationAgent properties are relevant for avoidance:
|
|
|
- The property ``neighbor_distance`` controls the search radius of the agent when searching for other agents that should be avoided. A lower value reduces processing cost.
|
|
|
- The property ``max_neighbors`` controls how many other agents are considered in the avoidance calculation if they all have overlapping radius.
|
|
|
A lower value reduces processing cost but a too low value may result in agents ignoring the avoidance.
|
|
|
- - The property ``time_horizion`` controls the avoidance maneuver start and end distance.
|
|
|
- How early and for how long an agents reacts to other agents within the ``neighbor_distance`` radius to correct its own velocity.
|
|
|
+ - The property ``time_horizion`` controls the avoidance maneuver start and end distance.
|
|
|
+ How early and for how long an agents reacts to other agents within the ``neighbor_distance`` radius to correct its own velocity.
|
|
|
A lower value results in avoidance kicking in with a very intense velocity change at a short distance while a high value results in very early but small velocity changes.
|
|
|
- The property ``max_speed`` controls the maximum velocity assumed for the agents avoidance calculation.
|
|
|
If the agents parents moves faster than this value the avoidance ``safe_velocity`` might not be accurate enough to avoid collision.
|
|
@@ -99,12 +99,12 @@ The ``velocity_computed`` signal of the agent node must be connected to receive
|
|
|
|
|
|
Additional the current velocity of the agents parent must be set for the agent in ``_physics_process()`` with ``set_velocity()``.
|
|
|
|
|
|
-After a short wait for processing the avoidance (still in the same frame) the ``safe_velocity`` vector will be received with the signal.
|
|
|
+After a short wait for processing the avoidance (still in the same frame) the ``safe_velocity`` vector will be received with the signal.
|
|
|
This velocity vector should be used to move the NavigationAgent's parent node in order to avoidance collision with other avoidance registered agents in proximity.
|
|
|
|
|
|
RVO exists in its own space and has no information from navigation meshes or physics collision.
|
|
|
Behind the scene avoidance agents are just circles with different radius on a flat plane.
|
|
|
-In narrow places obstructed with collision objects, the avoidance maneuver radius needs to be
|
|
|
+In narrow places obstructed with collision objects, the avoidance maneuver radius needs to be
|
|
|
reduced considerably or disabled else the avoidance velocity will get actors stuck on collision easily.
|
|
|
|
|
|
.. note::
|
|
@@ -113,19 +113,19 @@ reduced considerably or disabled else the avoidance velocity will get actors stu
|
|
|
|
|
|
.. warning::
|
|
|
|
|
|
- Actors that move according to their avoidance agent velocity will not move at
|
|
|
- full speed, can leave the navigation mesh bounds and can make movement
|
|
|
+ Actors that move according to their avoidance agent velocity will not move at
|
|
|
+ full speed, can leave the navigation mesh bounds and can make movement
|
|
|
pauses when the avoidance simulation becomes unsolvable.
|
|
|
|
|
|
-Using the NavigationAgent ``enable_avoidance`` property is the preferred option
|
|
|
-to toggle avoidance but the following scripts for NavigationAgents can be
|
|
|
+Using the NavigationAgent ``enable_avoidance`` property is the preferred option
|
|
|
+to toggle avoidance but the following scripts for NavigationAgents can be
|
|
|
used to create or delete avoidance callbacks for the agent RID.
|
|
|
|
|
|
.. tabs::
|
|
|
.. code-tab:: gdscript GDScript
|
|
|
|
|
|
extends NavigationAgent2D
|
|
|
-
|
|
|
+
|
|
|
var agent : RID = get_rid()
|
|
|
NavigationServer2D::get_singleton()->agent_set_callback(agent, self, "_avoidance_done")
|
|
|
NavigationServer2D::get_singleton()->agent_set_callback(agent, null, "_avoidance_done")
|
|
@@ -134,7 +134,7 @@ used to create or delete avoidance callbacks for the agent RID.
|
|
|
.. code-tab:: gdscript GDScript
|
|
|
|
|
|
extends NavigationAgent3D
|
|
|
-
|
|
|
+
|
|
|
var agent : RID = get_rid()
|
|
|
NavigationServer3D::get_singleton()->agent_set_callback(agent, self, "_avoidance_done")
|
|
|
NavigationServer3D::get_singleton()->agent_set_callback(agent, null, "_avoidance_done")
|
|
@@ -192,14 +192,14 @@ This script adds basic navigation movement to a CharacterBody3D with a Navigatio
|
|
|
navigation_agent.set_target_location(movement_target)
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
-
|
|
|
+
|
|
|
var next_path_position : Vector3 = navigation_agent.get_next_location()
|
|
|
var current_agent_position : Vector3 = global_transform.origin
|
|
|
var new_velocity : Vector3 = (next_path_position - current_agent_position).normalized() * movement_speed
|
|
|
navigation_agent.set_velocity(new_velocity)
|
|
|
|
|
|
func _on_NavigationAgent3D_velocity_computed(safe_velocity : Vector3):
|
|
|
- # Move KinematicBody3D with the computed `safe_velocity` to avoid dynamic obstacles.
|
|
|
+ # Move CharacterBody3D with the computed `safe_velocity` to avoid dynamic obstacles.
|
|
|
velocity = safe_velocity
|
|
|
move_and_slide()
|
|
|
|
|
@@ -220,12 +220,12 @@ This script adds basic navigation movement to a RigidBody3D with a NavigationAge
|
|
|
navigation_agent.set_target_location(movement_target)
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
-
|
|
|
+
|
|
|
var next_path_position : Vector3 = navigation_agent.get_next_location()
|
|
|
var current_agent_position : Vector3 = global_transform.origin
|
|
|
var new_velocity : Vector3 = (next_path_position - current_agent_position).normalized() * velocity
|
|
|
navigation_agent.set_velocity(new_velocity)
|
|
|
-
|
|
|
+
|
|
|
func _on_NavigationAgent3D_velocity_computed(safe_velocity : Vector3):
|
|
|
# Move RigidBody3D with the computed `safe_velocity` to avoid dynamic obstacles.
|
|
|
set_linear_velocity(safe_velocity)
|