CollisionPolygon2D
A node that provides a polygon shape to a CollisionObject2D parent.
A node that provides a polygon shape to a CollisionObject2D parent.
A node that provides a polygon shape to a CollisionObject2D parent and allows it to be edited. The polygon can be concave or convex. This can give a detection shape to an Area2D, turn a PhysicsBody2D into a solid object, or give a hollow shape to a StaticBody2D.
Warning: A non-uniformly scaled CollisionPolygon2D will likely not behave as expected. Make sure to keep its scale the same on all axes and adjust its polygon instead.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
CollisionPolygon2DConstructor
public CollisionPolygon2D();Properties6
BuildModeProperty
public CollisionPolygon2D.BuildModeEnum BuildMode { get; set; }Collision build mode.
DisabledProperty
public bool Disabled { get; set; }If true, no collisions will be detected. This property should be changed with ReckfellObject.SetDeferred.
OneWayCollisionProperty
public bool OneWayCollision { get; set; }If true, only edges that face up, relative to CollisionPolygon2D's rotation, will collide with other objects.
Note: This property has no effect if this CollisionPolygon2D is a child of an Area2D node.
Note: The one way collision direction can be configured by setting CollisionPolygon2D.OneWayCollisionDirection.
OneWayCollisionDirectionProperty
public Vector2 OneWayCollisionDirection { get; set; }The direction used for one-way collision.
OneWayCollisionMarginProperty
public float OneWayCollisionMargin { get; set; }The margin used for one-way collision (in pixels). Higher values will make the shape thicker, and work better for colliders that enter the polygon at a high velocity.
PolygonProperty
public Vector2[] Polygon { get; set; }The polygon's list of vertices. Each point will be connected to the next, and the final point will be connected to the first.
Note: The returned vertices are in the local coordinate space of the given CollisionPolygon2D.
Methods13
GetBuildModeCollisionPolygon2D.BuildModeEnum
public CollisionPolygon2D.BuildModeEnum GetBuildMode();CollisionPolygon2D.BuildModeEnumGetOneWayCollisionDirectionVector2
public Vector2 GetOneWayCollisionDirection();Vector2GetOneWayCollisionMarginfloat
public float GetOneWayCollisionMargin();floatGetPolygonVector2[]
public Vector2[] GetPolygon();Vector2[]IsDisabledbool
public bool IsDisabled();boolIsOneWayCollisionEnabledbool
public bool IsOneWayCollisionEnabled();boolSetBuildModevoid
public void SetBuildMode(CollisionPolygon2D.BuildModeEnum buildMode);| Name | Type | Default |
|---|---|---|
buildMode | CollisionPolygon2D.BuildModeEnum | — |
SetDisabledvoid
public void SetDisabled(bool disabled);| Name | Type | Default |
|---|---|---|
disabled | bool | — |
SetOneWayCollisionvoid
public void SetOneWayCollision(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetOneWayCollisionDirectionvoid
public void SetOneWayCollisionDirection(Vector2 direction);| Name | Type | Default |
|---|---|---|
direction | Vector2 | — |
SetOneWayCollisionMarginvoid
public void SetOneWayCollisionMargin(float margin);| Name | Type | Default |
|---|---|---|
margin | float | — |
SetPolygon2 overloads
public void SetPolygon(Vector2[] polygon);| Name | Type | Default |
|---|---|---|
polygon | Vector2[] | — |
public void SetPolygon(ReadOnlySpan<Vector2> polygon);| Name | Type | Default |
|---|---|---|
polygon | ReadOnlySpan<Vector2> | — |
CollisionPolygon2D.BuildModeEnum
| Value | Description |
|---|---|
Segments = 1 | Collisions will only include the polygon edges. In this mode the node has the same effect as a single |
Solids = 0 | Collisions will include the polygon and its contained area. In this mode the node has the same effect as several |