NavigationServer2D¶
Inherits: Object
Server interface for low-level 2D navigation access
Description¶
NavigationServer2D is the server responsible for all 2D navigation. It handles several objects, namely maps, regions and agents.
Maps are made up of regions, which are made of navigation polygons. Together, they define the navigable areas in the 2D world. For two regions to be connected to each other, they must share a similar edge. An edge is considered connected to another if both of its two vertices are at a distance less than edge_connection_margin
to the respective other edge's vertex.
You may assign navigation layers to regions with region_set_layers, which then can be checked upon when requesting a path with map_get_path. This allows allowing or forbidding some areas to 2D objects.
To use the collision avoidance system, you may use agents. You can set an agent's target velocity, then the servers will emit a callback with a modified velocity.
Note: The collision avoidance system ignores regions. Using the modified velocity as-is might lead to pushing and agent outside of a navigable area. This is a limitation of the collision avoidance system, any more complex situation may require the use of the physics engine.
This server keeps tracks of any call and executes them during the sync phase. This means that you can request any change to the map, using any thread, without worrying.
Tutorials¶
Methods¶
agent_create ( ) const |
|
agent_is_map_changed ( RID agent ) const |
|
void |
agent_set_callback ( RID agent, Object receiver, StringName method, Variant userdata=null ) const |
void |
agent_set_map ( RID agent, RID map ) const |
void |
agent_set_max_neighbors ( RID agent, int count ) const |
void |
agent_set_max_speed ( RID agent, float max_speed ) const |
void |
agent_set_neighbor_dist ( RID agent, float dist ) const |
void |
agent_set_position ( RID agent, Vector2 position ) const |
void |
agent_set_radius ( RID agent, float radius ) const |
void |
agent_set_target_velocity ( RID agent, Vector2 target_velocity ) const |
void |
agent_set_time_horizon ( RID agent, float time ) const |
void |
agent_set_velocity ( RID agent, Vector2 velocity ) const |
void |
|
map_create ( ) const |
|
map_get_cell_size ( RID map ) const |
|
map_get_closest_point ( RID map, Vector2 to_point ) const |
|
map_get_closest_point_owner ( RID map, Vector2 to_point ) const |
|
map_get_edge_connection_margin ( RID map ) const |
|
map_get_path ( RID map, Vector2 origin, Vector2 destination, bool optimize, int layers=1 ) const |
|
map_is_active ( RID nap ) const |
|
void |
map_set_active ( RID map, bool active ) const |
void |
map_set_cell_size ( RID map, float cell_size ) const |
void |
map_set_edge_connection_margin ( RID map, float margin ) const |
region_create ( ) const |
|
region_get_connection_pathway_end ( RID region, int connection ) const |
|
region_get_connection_pathway_start ( RID region, int connection ) const |
|
region_get_connections_count ( RID region ) const |
|
region_get_layers ( RID region ) const |
|
void |
region_set_layers ( RID region, int layers ) const |
void |
region_set_map ( RID region, RID map ) const |
void |
region_set_navpoly ( RID region, NavigationPolygon nav_poly ) const |
void |
region_set_transform ( RID region, Transform2D transform ) const |
Signals¶
map_changed ( RID map )
Emitted when a navigation map is updated, when a region moves or is modified.
Method Descriptions¶
RID agent_create ( ) const
Creates the agent.
Returns true if the map got changed the previous frame.
void agent_set_callback ( RID agent, Object receiver, StringName method, Variant userdata=null ) const
Callback called at the end of the RVO process.
Puts the agent in the map.
Sets the maximum number of other agents the agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
Sets the maximum speed of the agent. Must be positive.
Sets the maximum distance to other agents this agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
Sets the position of the agent in world space.
Sets the radius of the agent.
Sets the new target velocity.
The minimal amount of time for which the agent's velocities that are computed by the simulation are safe with respect to other agents. The larger this number, the sooner this agent will respond to the presence of other agents, but the less freedom this agent has in choosing its velocities. Must be positive.
Sets the current velocity of the agent.
void free ( RID object ) const
Destroy the RID
RID map_create ( ) const
Create a new map.
Returns the map cell size.
Returns the point closest to the provided to_point
on the navigation mesh surface.
Returns the owner region RID for the point returned by map_get_closest_point.
Returns the edge connection margin of the map. The edge connection margin is a distance used to connect two regions.
PackedVector2Array map_get_path ( RID map, Vector2 origin, Vector2 destination, bool optimize, int layers=1 ) const
Returns the navigation path to reach the destination from the origin. layers
is a bitmask of all region layers that are allowed to be in the path.
Returns true if the map is active.
Sets the map active.
Set the map cell size used to weld the navigation mesh polygons.
Set the map edge connection margin used to weld the compatible region edges.
RID region_create ( ) const
Creates a new region.
Returns the ending point of a connection door. connection
is an index between 0 and the return value of region_get_connections_count.
Returns the starting point of a connection door. connection
is an index between 0 and the return value of region_get_connections_count.
Returns how many connections this region
has with other regions in the map.
Returns the region's layers.
Set the region's layers. This allows selecting regions from a path request (when using map_get_path).
Sets the map for the region.
void region_set_navpoly ( RID region, NavigationPolygon nav_poly ) const
Sets the navigation mesh for the region.
void region_set_transform ( RID region, Transform2D transform ) const
Sets the global transformation for the region.