ShapeCast3D
A 3D shape that sweeps a region of space to detect CollisionObject3Ds.
A 3D shape that sweeps a region of space to detect CollisionObject3Ds.
Shape casting allows to detect collision objects by sweeping its ShapeCast3D.Shape along the cast direction determined by ShapeCast3D.TargetPosition. This is similar to RayCast3D, but it allows for sweeping a region of space, rather than just a straight line. ShapeCast3D 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 ShapeCast3D.TargetPosition set to Vector3(0, 0, 0) and by calling ShapeCast3D.ForceShapecastUpdate within the same physics frame. This helps to overcome some limitations of Area3D 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
ShapeCast3DConstructor
public ShapeCast3D();Properties11
CollideWithAreasProperty
public bool CollideWithAreas { get; set; }If true, collisions with Area3Ds will be reported.
CollideWithBodiesProperty
public bool CollideWithBodies { get; set; }If true, collisions with PhysicsBody3Ds will be reported.
CollisionMaskProperty
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
public Reckfell.Collections.Array CollisionResult { get; }Returns the complete collision information from the collision sweep. The data returned is the same as in the PhysicsDirectSpaceState3D.GetRestInfo method.
DebugShapeCustomColorProperty
public Color DebugShapeCustomColor { get; set; }The custom color to use to draw the shape in the editor and at run-time if Visible Collision Shapes is enabled in the Debug menu. This color will be highlighted at run-time if the ShapeCast3D is colliding with something.
If set to Color(0.0, 0.0, 0.0) (by default), the color set in ProjectSettings.debug/shapes/collision/shape_color is used.
EnabledProperty
public bool Enabled { get; set; }If true, collisions will be reported.
ExcludeParentProperty
public bool ExcludeParent { get; set; }If true, the parent node will be excluded from collision detection.
MarginProperty
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
public int MaxResults { get; set; }The number of intersections can be limited with this parameter, to reduce the processing time.
ShapeProperty
public Shape3D Shape { get; set; }The shape to be used for collision queries.
TargetPositionProperty
public Vector3 TargetPosition { get; set; }The shape's destination point, relative to this node's Entity3D.Position.
Methods39
AddExceptionvoid
public void AddException(CollisionObject3D node);Adds a collision exception so the shape does not report collisions with the specified node.
| Name | Type | Default |
|---|---|---|
node | CollisionObject3D | — |
AddExceptionRidvoid
public void AddExceptionRid(Rid rid);Adds a collision exception so the shape does not report collisions with the specified Rid.
| Name | Type | Default |
|---|---|---|
rid | Rid | — |
ClearExceptionsvoid
public void ClearExceptions();Removes all collision exceptions for this shape.
ForceShapecastUpdatevoid
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 ShapeCast3D.Enabled to true is not required for this to work.
GetClosestCollisionSafeFractionfloat
public float GetClosestCollisionSafeFraction();Returns the fraction from this cast's origin to its ShapeCast3D.TargetPosition of how far the shape can move without triggering a collision, as a value between 0.0 and 1.0.
floatGetClosestCollisionUnsafeFractionfloat
public float GetClosestCollisionUnsafeFraction();Returns the fraction from this cast's origin to its ShapeCast3D.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 ShapeCast3D.GetClosestCollisionSafeFraction, however shape casting is calculated in discrete steps, so the precise point of collision can occur between two calculated positions.
floatGetColliderReckfellObject
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. ShapeCast3D.IsColliding returns false).
| Name | Type | Default |
|---|---|---|
index | int | — |
ReckfellObjectGetColliderRidRid
public Rid GetColliderRid(int index);Returns the Rid of the collided object of one of the multiple collisions at index.
| Name | Type | Default |
|---|---|---|
index | int | — |
RidGetColliderShapeint
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. ShapeCast3D.IsColliding returns false).
| Name | Type | Default |
|---|---|---|
index | int | — |
intGetCollisionCountint
public int GetCollisionCount();The number of collisions detected at the point of impact. Use this to iterate over multiple collisions as provided by ShapeCast3D.GetCollider, ShapeCast3D.GetColliderShape, ShapeCast3D.GetCollisionPoint, and ShapeCast3D.GetCollisionNormal methods.
intGetCollisionMaskuint
public uint GetCollisionMask();uintGetCollisionMaskValuebool
public bool GetCollisionMaskValue(int layerNumber);Returns whether or not the specified layer of the ShapeCast3D.CollisionMask is enabled, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
boolGetCollisionNormalVector3
public Vector3 GetCollisionNormal(int index);Returns the normal of one of the multiple collisions at index of the intersecting object.
| Name | Type | Default |
|---|---|---|
index | int | — |
Vector3GetCollisionPointVector3
public Vector3 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.
| Name | Type | Default |
|---|---|---|
index | int | — |
Vector3GetCollisionResultReckfell.Collections.Array
public Reckfell.Collections.Array GetCollisionResult();Reckfell.Collections.ArrayGetDebugShapeCustomColorColor
public Color GetDebugShapeCustomColor();ColorGetExcludeParentBodybool
public bool GetExcludeParentBody();boolGetMarginfloat
public float GetMargin();floatGetMaxResultsint
public int GetMaxResults();intGetShapeShape3D
public Shape3D GetShape();Shape3DGetTargetPositionVector3
public Vector3 GetTargetPosition();Vector3IsCollideWithAreasEnabledbool
public bool IsCollideWithAreasEnabled();boolIsCollideWithBodiesEnabledbool
public bool IsCollideWithBodiesEnabled();boolIsCollidingbool
public bool IsColliding();Returns whether any object is intersecting with the shape's vector (considering the vector length).
boolIsEnabledbool
public bool IsEnabled();boolRemoveExceptionvoid
public void RemoveException(CollisionObject3D node);Removes a collision exception so the shape does report collisions with the specified node.
| Name | Type | Default |
|---|---|---|
node | CollisionObject3D | — |
RemoveExceptionRidvoid
public void RemoveExceptionRid(Rid rid);Removes a collision exception so the shape does report collisions with the specified Rid.
| Name | Type | Default |
|---|---|---|
rid | Rid | — |
ResourceChangedvoid · Deprecated
public void ResourceChanged(Resource resource);This method does nothing.
| Name | Type | Default |
|---|---|---|
resource | Resource | — |
SetCollideWithAreasvoid
public void SetCollideWithAreas(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetCollideWithBodiesvoid
public void SetCollideWithBodies(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetCollisionMaskvoid
public void SetCollisionMask(uint mask);| Name | Type | Default |
|---|---|---|
mask | uint | — |
SetCollisionMaskValuevoid
public void SetCollisionMaskValue(int layerNumber, bool value);Based on value, enables or disables the specified layer in the ShapeCast3D.CollisionMask, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
value | bool | — |
SetDebugShapeCustomColorvoid
public void SetDebugShapeCustomColor(Color debugShapeCustomColor);| Name | Type | Default |
|---|---|---|
debugShapeCustomColor | Color | — |
SetEnabledvoid
public void SetEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetExcludeParentBodyvoid
public void SetExcludeParentBody(bool mask);| Name | Type | Default |
|---|---|---|
mask | bool | — |
SetMarginvoid
public void SetMargin(float margin);| Name | Type | Default |
|---|---|---|
margin | float | — |
SetMaxResultsvoid
public void SetMaxResults(int maxResults);| Name | Type | Default |
|---|---|---|
maxResults | int | — |
SetShapevoid
public void SetShape(Shape3D shape);| Name | Type | Default |
|---|---|---|
shape | Shape3D | — |
SetTargetPositionvoid
public void SetTargetPosition(Vector3 localPoint);| Name | Type | Default |
|---|---|---|
localPoint | Vector3 | — |