NavigationObstacle2D
2D obstacle used to affect navigation mesh baking or constrain velocities of avoidance controlled agents.
2D obstacle used to affect navigation mesh baking or constrain velocities of avoidance controlled agents.
An obstacle needs a navigation map and outline NavigationObstacle2D.Vertices defined to work correctly. The outlines can not cross or overlap.
Obstacles can be included in the navigation mesh baking process when NavigationObstacle2D.AffectNavigationMesh 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. If NavigationObstacle2D.CarveNavigationMesh is enabled the baked shape will not be affected by offsets of the navigation mesh baking, e.g. the agent radius.
With NavigationObstacle2D.AvoidanceEnabled 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.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
NavigationObstacle2DConstructor
public NavigationObstacle2D();Properties7
AffectNavigationMeshProperty
public bool AffectNavigationMesh { get; set; }Allows the obstacle Entity to contribute during bake-source parsing. Enabling does not automatically rebake existing output: the checked old route stayed straight until explicit baking.
AvoidanceEnabledProperty
public bool AvoidanceEnabled { get; set; }Enables obstacle participation in avoidance on its assigned map. Does not make it a physics wall or automatically change a baked route.
AvoidanceLayersProperty
public uint AvoidanceLayers { get; set; }A bitfield determining the avoidance layers for this obstacle. Agents with a matching bit on the their avoidance mask will avoid this obstacle.
CarveNavigationMeshProperty
public bool CarveNavigationMesh { get; set; }Selects cutting after agent-radius offset during baking. A carve outline receives no additional radius clearance. Changing the flag does not itself start a bake.
RadiusProperty
public float Radius { get; set; }Dynamic avoidance-obstacle radius. May also contribute to bake-source data when AffectNavigationMesh is enabled. Not a physics-collider radius.
VelocityProperty
public Vector2 Velocity { get; set; }The wanted velocity for the obstacle, used by other agents to better predict the obstacle if it is moved with a velocity regularly (every frame), instead of warped to a new position.
Note: This property only affects avoidance for the obstacle's NavigationObstacle2D.Radius. Does nothing for the obstacle's static vertices.
VerticesProperty
public Vector2[] Vertices { get; set; }The outline vertices of the obstacle. If the vertices are winded in clockwise order, agents will be pushed in by the obstacle, otherwise they will be pushed out. Outlines cannot be crossed or overlap. If the obstacle is warped to a new position, agents cannot predict this movement and may get trapped inside the obstacle.
Methods20
GetAffectNavigationMeshbool
public bool GetAffectNavigationMesh();boolGetAvoidanceEnabledbool
public bool GetAvoidanceEnabled();boolGetAvoidanceLayerValuebool
public bool GetAvoidanceLayerValue(int layerNumber);Returns whether or not the specified layer of the NavigationObstacle2D.AvoidanceLayers bitmask is enabled, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
boolGetAvoidanceLayersuint
public uint GetAvoidanceLayers();uintGetCarveNavigationMeshbool
public bool GetCarveNavigationMesh();boolGetNavigationMapRid
public Rid GetNavigationMap();Returns the Rid 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. Use NavigationObstacle2D.SetNavigationMap to change the navigation map for the NavigationObstacle and also update the obstacle on the NavigationServer.
RidGetRadiusfloat
public float GetRadius();floatGetRidRid
public Rid GetRid();Returns the Rid of this obstacle on the NavigationServer2D.
RidGetVelocityVector2
public Vector2 GetVelocity();Vector2GetVerticesVector2[]
public Vector2[] GetVertices();Vector2[]SetAffectNavigationMeshvoid
public void SetAffectNavigationMesh(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetAvoidanceEnabledvoid
public void SetAvoidanceEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetAvoidanceLayerValuevoid
public void SetAvoidanceLayerValue(int layerNumber, bool value);Based on value, enables or disables the specified layer in the NavigationObstacle2D.AvoidanceLayers bitmask, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
value | bool | — |
SetAvoidanceLayersvoid
public void SetAvoidanceLayers(uint layers);| Name | Type | Default |
|---|---|---|
layers | uint | — |
SetCarveNavigationMeshvoid
public void SetCarveNavigationMesh(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetNavigationMapvoid
public void SetNavigationMap(Rid navigationMap);Sets the Rid of the navigation map this NavigationObstacle node should use and also updates the obstacle on the NavigationServer.
| Name | Type | Default |
|---|---|---|
navigationMap | Rid | — |
SetRadiusvoid
public void SetRadius(float radius);| Name | Type | Default |
|---|---|---|
radius | float | — |
SetVelocityvoid
public void SetVelocity(Vector2 velocity);| Name | Type | Default |
|---|---|---|
velocity | Vector2 | — |
SetVertices2 overloads
public void SetVertices(Vector2[] vertices);| Name | Type | Default |
|---|---|---|
vertices | Vector2[] | — |
public void SetVertices(ReadOnlySpan<Vector2> vertices);| Name | Type | Default |
|---|---|---|
vertices | ReadOnlySpan<Vector2> | — |