NavigationObstacle2D

实验性: This class may be changed or removed in future versions.

继承: Node2D < CanvasItem < Node < Object

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

描述

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 affect_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. If carve_navigation_mesh is enabled the baked shape will not be affected by offsets of the navigation mesh baking, e.g. the agent radius.

With avoidance_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.

属性

方法

boolget_avoidance_layer_value ( layer_number: int ) const1
RIDget_navigation_map ( ) const1
RIDget_rid ( ) const1
voidset_avoidance_layer_value ( layer_number: int, value: bool )
voidset_navigation_map ( navigation_map: RID )

属性说明

bool affect_navigation_mesh = false

  • void set_affect_navigation_mesh ( value: bool )
  • bool get_affect_navigation_mesh ( )

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


bool avoidance_enabled = true

  • void set_avoidance_enabled ( value: bool )
  • bool get_avoidance_enabled ( )

If true the obstacle affects avoidance using agents.


int avoidance_layers = 1

  • void set_avoidance_layers ( value: int )
  • int get_avoidance_layers ( )

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


bool carve_navigation_mesh = false

  • void set_carve_navigation_mesh ( value: bool )
  • bool get_carve_navigation_mesh ( )

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 affect_navigation_mesh to be enabled.


float radius = 0.0

  • void set_radius ( value: float )
  • float get_radius ( )

Sets the avoidance radius for the obstacle.


Vector2 velocity = 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 obstacles radius. Does nothing for the obstacles static vertices.


PackedVector2Array vertices = 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 is copied and any changes to it will not update the original property value. See PackedVector2Array for more details.


方法说明

bool get_avoidance_layer_value ( layer_number: int ) const1

Returns whether or not the specified layer of the avoidance_layers bitmask is enabled, given a layer_number between 1 and 32.


RID get_navigation_map ( ) const1

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 set_navigation_map to change the navigation map for the NavigationObstacle and also update the obstacle on the NavigationServer.


RID get_rid ( ) const1

Returns the RID of this obstacle on the NavigationServer2D.


void set_avoidance_layer_value ( layer_number: int, value: bool )

Based on value, enables or disables the specified layer in the avoidance_layers bitmask, given a layer_number between 1 and 32.


void set_navigation_map ( navigation_map: RID )

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

2

本方法通常需要用户覆盖才能生效。

1

本方法无副作用,不会修改该实例的任何成员变量。

3

本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。

4

本方法用于构造某个类型。

5

调用本方法无需实例,可直接使用类名进行调用。

6

本方法描述的是使用本类型作为左操作数的有效运算符。

7

这个值是由下列位标志构成位掩码的整数。

8

无返回值。