reckfellENGINE

ShapeCast2D

A 2D shape that sweeps a region of space to detect CollisionObject2Ds.

On this page
class ShapeCast2DReckfellSharpInherits Entity2D

A 2D shape that sweeps a region of space to detect CollisionObject2Ds.

Shape casting allows to detect collision objects by sweeping its ShapeCast2D.Shape along the cast direction determined by ShapeCast2D.TargetPosition. This is similar to RayCast2D, but it allows for sweeping a region of space, rather than just a straight line. ShapeCast2D can detect multiple collision objects. It is useful for things like wide laser beams or snapping a simple shape to a floor. Immediate collision overlaps can be done with the ShapeCast2D.TargetPosition set to Vector2(0, 0) and by calling ShapeCast2D.ForceShapecastUpdate within the same physics frame. This helps to overcome some limitations of Area2D when used as an instantaneous detection area, as collision information isn't immediately available to it. Note: Shape casting is more computationally expensive than ray casting.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

ShapeCast2DConstructor
# ShapeCast2D
C#
public ShapeCast2D();

Properties10

CollideWithAreasProperty
# CollideWithAreas
C#
public bool CollideWithAreas { get; set; }

If true, collisions with Area2Ds will be reported.

CollideWithBodiesProperty
# CollideWithBodies
C#
public bool CollideWithBodies { get; set; }

If true, collisions with PhysicsBody2Ds will be reported.

CollisionMaskProperty
# CollisionMask
C#
public uint CollisionMask { get; set; }

The shape's collision mask. Only objects in at least one collision layer enabled in the mask will be detected. See Collision layers and masks in the documentation for more information.

CollisionResultProperty
# CollisionResult
C#
public Reckfell.Collections.Array CollisionResult { get; }

Returns the complete collision information from the collision sweep. The data returned is the same as in the PhysicsDirectSpaceState2D.GetRestInfo method.

EnabledProperty
# Enabled
C#
public bool Enabled { get; set; }

If true, collisions will be reported.

ExcludeParentProperty
# ExcludeParent
C#
public bool ExcludeParent { get; set; }

If true, the parent node will be excluded from collision detection.

MarginProperty
# Margin
C#
public float Margin { get; set; }

The collision margin for the shape. A larger margin helps detecting collisions more consistently, at the cost of precision.

MaxResultsProperty
# MaxResults
C#
public int MaxResults { get; set; }

The number of intersections can be limited with this parameter, to reduce the processing time.

ShapeProperty
# Shape
C#
public Shape2D Shape { get; set; }

The shape to be used for collision queries.

TargetPositionProperty
# TargetPosition
C#
public Vector2 TargetPosition { get; set; }

The shape's destination point, relative to this node's Entity2D.Position.

Methods36

AddExceptionvoid
# AddException
C#
public void AddException(CollisionObject2D node);

Adds a collision exception so the shape does not report collisions with the specified node.

Parameters
NameTypeDefault
nodeCollisionObject2D—
AddExceptionRidvoid
# AddExceptionRid
C#
public void AddExceptionRid(Rid rid);

Adds a collision exception so the shape does not report collisions with the specified Rid.

Parameters
NameTypeDefault
ridRid—
ClearExceptionsvoid
# ClearExceptions
C#
public void ClearExceptions();

Removes all collision exceptions for this shape.

ForceShapecastUpdatevoid
# ForceShapecastUpdate
C#
public void ForceShapecastUpdate();

Updates the collision information for the shape immediately, without waiting for the next _physics_process call. Use this method, for example, when the shape or its parent has changed state. Note: Setting ShapeCast2D.Enabled to true is not required for this to work.

GetClosestCollisionSafeFractionfloat
# GetClosestCollisionSafeFraction
C#
public float GetClosestCollisionSafeFraction();

Returns the fraction from this cast's origin to its ShapeCast2D.TargetPosition of how far the shape can move without triggering a collision, as a value between 0.0 and 1.0.

Returns float
GetClosestCollisionUnsafeFractionfloat
# GetClosestCollisionUnsafeFraction
C#
public float GetClosestCollisionUnsafeFraction();

Returns the fraction from this cast's origin to its ShapeCast2D.TargetPosition of how far the shape must move to trigger a collision, as a value between 0.0 and 1.0. In ideal conditions this would be the same as ShapeCast2D.GetClosestCollisionSafeFraction, however shape casting is calculated in discrete steps, so the precise point of collision can occur between two calculated positions.

Returns float
GetColliderReckfellObject
# GetCollider
C#
public ReckfellObject GetCollider(int index);

Returns the collided ReckfellObject of one of the multiple collisions at index, or null if no object is intersecting the shape (i.e. ShapeCast2D.IsColliding returns false).

Parameters
NameTypeDefault
indexint—
Returns ReckfellObject
GetColliderRidRid
# GetColliderRid
C#
public Rid GetColliderRid(int index);

Returns the Rid of the collided object of one of the multiple collisions at index.

Parameters
NameTypeDefault
indexint—
Returns Rid
GetColliderShapeint
# GetColliderShape
C#
public int GetColliderShape(int index);

Returns the shape ID of the colliding shape of one of the multiple collisions at index, or 0 if no object is intersecting the shape (i.e. ShapeCast2D.IsColliding returns false).

Parameters
NameTypeDefault
indexint—
Returns int
GetCollisionCountint
# GetCollisionCount
C#
public int GetCollisionCount();

The number of collisions detected at the point of impact. Use this to iterate over multiple collisions as provided by ShapeCast2D.GetCollider, ShapeCast2D.GetColliderShape, ShapeCast2D.GetCollisionPoint, and ShapeCast2D.GetCollisionNormal methods.

Returns int
GetCollisionMaskuint
# GetCollisionMask
C#
public uint GetCollisionMask();
Returns uint
GetCollisionMaskValuebool
# GetCollisionMaskValue
C#
public bool GetCollisionMaskValue(int layerNumber);

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

Parameters
NameTypeDefault
layerNumberint—
Returns bool
GetCollisionNormalVector2
# GetCollisionNormal
C#
public Vector2 GetCollisionNormal(int index);

Returns the normal of one of the multiple collisions at index of the intersecting object.

Parameters
NameTypeDefault
indexint—
Returns Vector2
GetCollisionPointVector2
# GetCollisionPoint
C#
public Vector2 GetCollisionPoint(int index);

Returns the collision point of one of the multiple collisions at index where the shape intersects the colliding object. Note: This point is in the global coordinate system.

Parameters
NameTypeDefault
indexint—
Returns Vector2
GetCollisionResultReckfell.Collections.Array
# GetCollisionResult
C#
public Reckfell.Collections.Array GetCollisionResult();
Returns Reckfell.Collections.Array
GetExcludeParentBodybool
# GetExcludeParentBody
C#
public bool GetExcludeParentBody();
Returns bool
GetMarginfloat
# GetMargin
C#
public float GetMargin();
Returns float
GetMaxResultsint
# GetMaxResults
C#
public int GetMaxResults();
Returns int
GetShapeShape2D
# GetShape
C#
public Shape2D GetShape();
Returns Shape2D
GetTargetPositionVector2
# GetTargetPosition
C#
public Vector2 GetTargetPosition();
Returns Vector2
IsCollideWithAreasEnabledbool
# IsCollideWithAreasEnabled
C#
public bool IsCollideWithAreasEnabled();
Returns bool
IsCollideWithBodiesEnabledbool
# IsCollideWithBodiesEnabled
C#
public bool IsCollideWithBodiesEnabled();
Returns bool
IsCollidingbool
# IsColliding
C#
public bool IsColliding();

Returns whether any object is intersecting with the shape's vector (considering the vector length).

Returns bool
IsEnabledbool
# IsEnabled
C#
public bool IsEnabled();
Returns bool
RemoveExceptionvoid
# RemoveException
C#
public void RemoveException(CollisionObject2D node);

Removes a collision exception so the shape does report collisions with the specified node.

Parameters
NameTypeDefault
nodeCollisionObject2D—
RemoveExceptionRidvoid
# RemoveExceptionRid
C#
public void RemoveExceptionRid(Rid rid);

Removes a collision exception so the shape does report collisions with the specified Rid.

Parameters
NameTypeDefault
ridRid—
SetCollideWithAreasvoid
# SetCollideWithAreas
C#
public void SetCollideWithAreas(bool enable);
Parameters
NameTypeDefault
enablebool—
SetCollideWithBodiesvoid
# SetCollideWithBodies
C#
public void SetCollideWithBodies(bool enable);
Parameters
NameTypeDefault
enablebool—
SetCollisionMaskvoid
# SetCollisionMask
C#
public void SetCollisionMask(uint mask);
Parameters
NameTypeDefault
maskuint—
SetCollisionMaskValuevoid
# SetCollisionMaskValue
C#
public void SetCollisionMaskValue(int layerNumber, bool value);

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

Parameters
NameTypeDefault
layerNumberint—
valuebool—
SetEnabledvoid
# SetEnabled
C#
public void SetEnabled(bool enabled);
Parameters
NameTypeDefault
enabledbool—
SetExcludeParentBodyvoid
# SetExcludeParentBody
C#
public void SetExcludeParentBody(bool mask);
Parameters
NameTypeDefault
maskbool—
SetMarginvoid
# SetMargin
C#
public void SetMargin(float margin);
Parameters
NameTypeDefault
marginfloat—
SetMaxResultsvoid
# SetMaxResults
C#
public void SetMaxResults(int maxResults);
Parameters
NameTypeDefault
maxResultsint—
SetShapevoid
# SetShape
C#
public void SetShape(Shape2D shape);
Parameters
NameTypeDefault
shapeShape2D—
SetTargetPositionvoid
# SetTargetPosition
C#
public void SetTargetPosition(Vector2 localPoint);
Parameters
NameTypeDefault
localPointVector2—
Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.