CollisionShape2D
Attaches a shape resource to a 2D body or area.
CollisionShape2D must be a direct child of a suitable CollisionObject. Shape is shared: resizing a common resource affects every instance using it. Assign a Duplicate before editing independent geometry.
Change resource dimensions with unit scale in the physics branch, including inherited scale checks. Disabled removes the shape from physics participation after application. Use SetDeferred inside a physics signal rather than immediate restructuring. Hiding the visible model does not disable collision.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
CollisionShape2DConstructor
public CollisionShape2D();Properties6
DebugColorProperty
public Color DebugColor { get; set; }The collision shape color that is displayed in the editor, or in the running project if Debug > Visible Collision Shapes is checked at the top of the editor.
Note: The default value is ProjectSettings.debug/shapes/collision/shape_color. The Color(0, 0, 0, 0) value documented here is a placeholder, and not the actual default debug color.
DisabledProperty
public bool Disabled { get; set; }Excludes the shape from physics participation after application. Use SetDeferred from a physics callback; hiding artwork does not substitute for this flag.
OneWayCollisionProperty
public bool OneWayCollision { get; set; }Sets whether this collision shape should only detect collision on one side (top or bottom).
Note: This property has no effect if this CollisionShape2D is a child of an Area2D node.
Note: The one way collision direction can be configured by setting CollisionShape2D.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 shape at a high velocity.
ShapeProperty
public Shape2D Shape { get; set; }A geometry resource that can be shared across instances. Resizing affects all users; assign a Duplicate first for an independent collider.
Methods12
GetDebugColorColor
public Color GetDebugColor();ColorGetOneWayCollisionDirectionVector2
public Vector2 GetOneWayCollisionDirection();Vector2GetOneWayCollisionMarginfloat
public float GetOneWayCollisionMargin();floatGetShapeShape2D
public Shape2D GetShape();Shape2DIsDisabledbool
public bool IsDisabled();boolIsOneWayCollisionEnabledbool
public bool IsOneWayCollisionEnabled();boolSetDebugColorvoid
public void SetDebugColor(Color color);| Name | Type | Default |
|---|---|---|
color | Color | — |
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 | — |
SetShapevoid
public void SetShape(Shape2D shape);| Name | Type | Default |
|---|---|---|
shape | Shape2D | — |