Table of Contents

Class Shape2D

Namespace
Godot
Assembly
GodotSharp.dll

Abstract base class for all 2D shapes, intended for use in physics.

Performance: Primitive shapes, especially CircleShape2D, are fast to check collisions against. ConvexPolygonShape2D is slower, and ConcavePolygonShape2D is the slowest.

public class Shape2D : Resource, IDisposable
Inheritance
Shape2D
Implements
Derived
Inherited Members

Properties

CustomSolverBias

The shape's custom solver bias. Defines how much bodies react to enforce contact separation when this shape is involved.

When set to 0, the default value from ProjectSettings.physics/2d/solver/default_contact_bias is used.

public float CustomSolverBias { get; set; }

Property Value

float

Methods

Collide(Transform2D, Shape2D, Transform2D)

Returns true if this shape is colliding with another.

This method needs the transformation matrix for this shape (localXform), the shape to check collisions with (withShape), and the transformation matrix of that shape (shapeXform).

public bool Collide(Transform2D localXform, Shape2D withShape, Transform2D shapeXform)

Parameters

localXform Transform2D
withShape Shape2D
shapeXform Transform2D

Returns

bool

CollideAndGetContacts(Transform2D, Shape2D, Transform2D)

Returns a list of contact point pairs where this shape touches another.

If there are no collisions, the returned list is empty. Otherwise, the returned list contains contact points arranged in pairs, with entries alternating between points on the boundary of this shape and points on the boundary of withShape.

A collision pair A, B can be used to calculate the collision normal with (B - A).normalized(), and the collision depth with (B - A).length(). This information is typically used to separate shapes, particularly in collision solvers.

This method needs the transformation matrix for this shape (localXform), the shape to check collisions with (withShape), and the transformation matrix of that shape (shapeXform).

public Vector2[] CollideAndGetContacts(Transform2D localXform, Shape2D withShape, Transform2D shapeXform)

Parameters

localXform Transform2D
withShape Shape2D
shapeXform Transform2D

Returns

Vector2[]

CollideWithMotion(Transform2D, Vector2, Shape2D, Transform2D, Vector2)

Returns whether this shape would collide with another, if a given movement was applied.

This method needs the transformation matrix for this shape (localXform), the movement to test on this shape (localMotion), the shape to check collisions with (withShape), the transformation matrix of that shape (shapeXform), and the movement to test onto the other object (shapeMotion).

public bool CollideWithMotion(Transform2D localXform, Vector2 localMotion, Shape2D withShape, Transform2D shapeXform, Vector2 shapeMotion)

Parameters

localXform Transform2D
localMotion Vector2
withShape Shape2D
shapeXform Transform2D
shapeMotion Vector2

Returns

bool

CollideWithMotionAndGetContacts(Transform2D, Vector2, Shape2D, Transform2D, Vector2)

Returns a list of contact point pairs where this shape would touch another, if a given movement was applied.

If there would be no collisions, the returned list is empty. Otherwise, the returned list contains contact points arranged in pairs, with entries alternating between points on the boundary of this shape and points on the boundary of withShape.

A collision pair A, B can be used to calculate the collision normal with (B - A).normalized(), and the collision depth with (B - A).length(). This information is typically used to separate shapes, particularly in collision solvers.

This method needs the transformation matrix for this shape (localXform), the movement to test on this shape (localMotion), the shape to check collisions with (withShape), the transformation matrix of that shape (shapeXform), and the movement to test onto the other object (shapeMotion).

public Vector2[] CollideWithMotionAndGetContacts(Transform2D localXform, Vector2 localMotion, Shape2D withShape, Transform2D shapeXform, Vector2 shapeMotion)

Parameters

localXform Transform2D
localMotion Vector2
withShape Shape2D
shapeXform Transform2D
shapeMotion Vector2

Returns

Vector2[]

Draw(Rid, Color)

Draws a solid shape onto a CanvasItem with the RenderingServer API filled with the specified color. The exact drawing method is specific for each shape and cannot be configured.

public void Draw(Rid canvasItem, Color color)

Parameters

canvasItem Rid
color Color

GetRect()

Returns a Rect2 representing the shapes boundary.

public Rect2 GetRect()

Returns

Rect2

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_name

Name of the method to check for.

Returns

bool

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_name

Name of the signal to check for.

Returns

bool

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_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool