NavigationObstacle2D

Experimental: This class may be changed or removed in future versions.

Inherits:Node2D<CanvasItem<Node<Object

2D obstacle used to affect navigation mesh baking or constrain velocities of avoidance controlled agents.

Description

An obstacle needs a navigation map and outlinevertices defined to work correctly. The outlines can not cross or overlap.

Obstacles can be included in the navigation mesh baking process whenaffect_navigation_mesh is enabled. They do not add walkable geometry, instead their role is to discard other source geometry inside the shape. This can be used to prevent navigation mesh from appearing in unwanted places. Ifcarve_navigation_mesh is enabled the baked shape will not be affected by offsets of the navigation mesh baking, e.g. the agent radius.

Withavoidance_enabled the obstacle can constrain the avoidance velocities of avoidance using agents. If the obstacle's vertices are wound in clockwise order, avoidance agents will be pushed in by the obstacle, otherwise, avoidance agents will be pushed out. Obstacles using vertices and avoidance can warp to a new position but should not be moved every single frame as each change requires a rebuild of the avoidance map.

Tutorials

Properties

bool

affect_navigation_mesh

false

bool

avoidance_enabled

true

int

avoidance_layers

1

bool

carve_navigation_mesh

false

float

radius

0.0

Vector2

velocity

Vector2(0,0)

PackedVector2Array

vertices

PackedVector2Array()

Methods

bool

get_avoidance_layer_value(layer_number:int)const

RID

get_navigation_map()const

RID

get_rid()const

void

set_avoidance_layer_value(layer_number:int, value:bool)

void

set_navigation_map(navigation_map:RID)


Property Descriptions

boolaffect_navigation_mesh =false🔗

If enabled and parsed in a navigation mesh baking process the obstacle will discard source geometry inside itsvertices defined shape.


boolavoidance_enabled =true🔗

Iftrue the obstacle affects avoidance using agents.


intavoidance_layers =1🔗

A bitfield determining the avoidance layers for this obstacle. Agents with a matching bit on the their avoidance mask will avoid this obstacle.


boolcarve_navigation_mesh =false🔗

If enabled the obstacle vertices will carve into the baked navigation mesh with the shape unaffected by additional offsets (e.g. agent radius).

It will still be affected by further postprocessing of the baking process, like edge and polygon simplification.

Requiresaffect_navigation_mesh to be enabled.


floatradius =0.0🔗

Sets the avoidance radius for the obstacle.


Vector2velocity =Vector2(0,0)🔗

Sets the wanted velocity for the obstacle so other agent's can better predict the obstacle if it is moved with a velocity regularly (every frame) instead of warped to a new position. Does only affect avoidance for the obstaclesradius. Does nothing for the obstacles static vertices.


PackedVector2Arrayvertices =PackedVector2Array()🔗

The outline vertices of the obstacle. If the vertices are winded in clockwise order agents will be pushed in by the obstacle, else they will be pushed out. Outlines can not be crossed or overlap. Should the vertices using obstacle be warped to a new position agent's can not predict this movement and may get trapped inside the obstacle.

Note: The returned array iscopied and any changes to it will not update the original property value. SeePackedVector2Array for more details.


Method Descriptions

boolget_avoidance_layer_value(layer_number:int)const🔗

Returns whether or not the specified layer of theavoidance_layers bitmask is enabled, given alayer_number between 1 and 32.


RIDget_navigation_map()const🔗

Returns theRID of the navigation map for this NavigationObstacle node. This function returns always the map set on the NavigationObstacle node and not the map of the abstract obstacle on the NavigationServer. If the obstacle map is changed directly with the NavigationServer API the NavigationObstacle node will not be aware of the map change. Useset_navigation_map() to change the navigation map for the NavigationObstacle and also update the obstacle on the NavigationServer.


RIDget_rid()const🔗

Returns theRID of this obstacle on theNavigationServer2D.


voidset_avoidance_layer_value(layer_number:int, value:bool)🔗

Based onvalue, enables or disables the specified layer in theavoidance_layers bitmask, given alayer_number between 1 and 32.


voidset_navigation_map(navigation_map:RID)🔗

Sets theRID of the navigation map this NavigationObstacle node should use and also updates theobstacle on the NavigationServer.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.