Class NavigationObstacle2D
- Namespace
- Godot
- Assembly
- GodotSharp.dll
An obstacle needs a navigation map and outline Vertices defined to work correctly. The outlines can not cross or overlap.
Obstacles can be included in the navigation mesh baking process when 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 CarveNavigationMesh is enabled the baked shape will not be affected by offsets of the navigation mesh baking, e.g. the agent radius.
With 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.
public class NavigationObstacle2D : Node2D, IDisposable
- Inheritance
-
NavigationObstacle2D
- Implements
- Inherited Members
Constructors
NavigationObstacle2D()
public NavigationObstacle2D()
Properties
AffectNavigationMesh
If enabled and parsed in a navigation mesh baking process the obstacle will discard source geometry inside its Vertices defined shape.
public bool AffectNavigationMesh { get; set; }
Property Value
AvoidanceEnabled
If true the obstacle affects avoidance using agents.
public bool AvoidanceEnabled { get; set; }
Property Value
AvoidanceLayers
A bitfield determining the avoidance layers for this obstacle. Agents with a matching bit on the their avoidance mask will avoid this obstacle.
public uint AvoidanceLayers { get; set; }
Property Value
CarveNavigationMesh
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.
Requires AffectNavigationMesh to be enabled.
public bool CarveNavigationMesh { get; set; }
Property Value
Radius
Sets the avoidance radius for the obstacle.
public float Radius { get; set; }
Property Value
Velocity
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 obstacles Radius. Does nothing for the obstacles static vertices.
public Vector2 Velocity { get; set; }
Property Value
Vertices
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.
public Vector2[] Vertices { get; set; }
Property Value
- Vector2[]
Methods
GetAvoidanceLayerValue(int)
Returns whether or not the specified layer of the AvoidanceLayers bitmask is enabled, given a layerNumber
between 1 and 32.
public bool GetAvoidanceLayerValue(int layerNumber)
Parameters
layerNumber
int
Returns
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 SetNavigationMap(Rid) to change the navigation map for the NavigationObstacle and also update the obstacle on the NavigationServer.
public Rid GetNavigationMap()
Returns
GetRid()
Returns the Rid of this obstacle on the NavigationServer2D.
public Rid GetRid()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
SetAvoidanceLayerValue(int, bool)
Based on value
, enables or disables the specified layer in the AvoidanceLayers bitmask, given a layerNumber
between 1 and 32.
public void SetAvoidanceLayerValue(int layerNumber, bool value)
Parameters
SetNavigationMap(Rid)
Sets the Rid of the navigation map this NavigationObstacle node should use and also updates the obstacle
on the NavigationServer.
public void SetNavigationMap(Rid navigationMap)
Parameters
navigationMap
Rid