Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
NavigationAgent2D¶
A 2D agent used to pathfind to a position while avoiding obstacles.
Description¶
A 2D agent used to pathfind to a position while avoiding static and dynamic obstacles. The calculation can be used by the parent node to dynamically move it along the path. Requires navigation data to work correctly.
Dynamic obstacles are avoided using RVO collision avoidance. Avoidance is computed before physics, so the pathfinding information can be used safely in the physics step.
Note: After setting the target_position property, the get_next_path_position method must be used once every physics frame to update the internal path logic of the navigation agent. The vector position it returns should be used as the next movement position for the agent's parent node.
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
BitField<PathMetadataFlags> |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
distance_to_target ( ) const |
|
get_avoidance_layer_value ( int layer_number ) const |
|
get_avoidance_mask_value ( int mask_number ) const |
|
get_current_navigation_path ( ) const |
|
get_current_navigation_path_index ( ) const |
|
get_current_navigation_result ( ) const |
|
get_navigation_layer_value ( int layer_number ) const |
|
get_navigation_map ( ) const |
|
get_rid ( ) const |
|
is_target_reached ( ) const |
|
void |
set_avoidance_layer_value ( int layer_number, bool value ) |
void |
set_avoidance_mask_value ( int mask_number, bool value ) |
void |
set_navigation_layer_value ( int layer_number, bool value ) |
void |
set_navigation_map ( RID navigation_map ) |
void |
set_velocity_forced ( Vector2 velocity ) |
Signals¶
link_reached ( Dictionary details )
Notifies when a navigation link has been reached.
The details dictionary may contain the following keys depending on the value of path_metadata_flags:
position
: The start position of the link that was reached.type
: Always NavigationPathQueryResult2D.PATH_SEGMENT_TYPE_LINK.rid
: The RID of the link.owner
: The object which manages the link (usually NavigationLink2D).link_entry_position
: Ifowner
is available and the owner is a NavigationLink2D, it will contain the global position of the link's point the agent is entering.link_exit_position
: Ifowner
is available and the owner is a NavigationLink2D, it will contain the global position of the link's point which the agent is exiting.
navigation_finished ( )
Emitted once per loaded path when the agent internal navigation path index reaches the last index of the loaded path array. The agent internal navigation path index can be received with get_current_navigation_path_index.
path_changed ( )
Emitted when the agent had to update the loaded path:
because path was previously empty.
because navigation map has changed.
because agent pushed further away from the current path segment than the path_max_distance.
target_reached ( )
Emitted once per loaded path when the agent's global position is the first time within target_desired_distance to the target_position.
velocity_computed ( Vector2 safe_velocity )
Notifies when the collision avoidance velocity is calculated. Emitted when velocity is set. Only emitted when avoidance_enabled is true.
waypoint_reached ( Dictionary details )
Notifies when a waypoint