class Shape2D
package godot
extends Resource › Reference › Object
extended by CapsuleShape2D, CircleShape2D, ConcavePolygonShape2D, ConvexPolygonShape2D, LineShape2D, RayShape2D, RectangleShape2D, SegmentShape2D
Base class for all 2D shapes. All 2D shape types inherit from this.
Variables
Methods
collide(localXform:Transform2D, withShape:Shape2D, shapeXform:Transform2D):Bool
Returns true
if this shape is colliding with another.
This method needs the transformation matrix for this shape (local_xform
), the shape to check collisions with (with_shape
), and the transformation matrix of that shape (shape_xform
).
collideAndGetContacts(localXform:Transform2D, withShape:Shape2D, shapeXform:Transform2D):Array
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 with_shape
.
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 (local_xform
), the shape to check collisions with (with_shape
), and the transformation matrix of that shape (shape_xform
).
collideWithMotion(localXform:Transform2D, localMotion:Vector2, withShape:Shape2D, shapeXform:Transform2D, shapeMotion:Vector2):Bool
Returns whether this shape would collide with another, if a given movement was applied.
This method needs the transformation matrix for this shape (local_xform
), the movement to test on this shape (local_motion
), the shape to check collisions with (with_shape
), the transformation matrix of that shape (shape_xform
), and the movement to test onto the other object (shape_motion
).
collideWithMotionAndGetContacts(localXform:Transform2D, localMotion:Vector2, withShape:Shape2D, shapeXform:Transform2D, shapeMotion:Vector2):Array
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 with_shape
.
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 (local_xform
), the movement to test on this shape (local_motion
), the shape to check collisions with (with_shape
), the transformation matrix of that shape (shape_xform
), and the movement to test onto the other object (shape_motion
).
draw(canvasItem:RID, color:Color):Void
Draws a solid shape onto a godot.CanvasItem
with the godot.VisualServer
API filled with the specified color
. The exact drawing method is specific for each shape and cannot be configured.