reckfellENGINE

RayCast3D

A 3D ray-query entity with an updated result.

On this page
class RayCast3DReckfellSharpInherits Entity3D

RayCast3D tests a segment from its world position to the transformed TargetPosition. TargetPosition is a local endpoint, not a world coordinate. After IsColliding, read the collider, point and normal.

Results update in the physics phase. ForceRaycastUpdate requests an update now, even with Enabled = false, but does not advance the whole simulation. Configure Mask, body/area categories and exclusions. Inside hits can have zero normals; check before normalizing.

Guide and example.

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

Constructors1

RayCast3DConstructor
# RayCast3D
C#
public RayCast3D();

Properties10

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

If true, collisions with Area3Ds will be reported.

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

If true, collisions with PhysicsBody3Ds will be reported.

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

The ray'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.

DebugShapeCustomColorProperty
# DebugShapeCustomColor
C#
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 RayCast3D 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.

DebugShapeThicknessProperty
# DebugShapeThickness
C#
public int DebugShapeThickness { get; set; }

If set to 1, a line is used as the debug shape. Otherwise, a truncated pyramid is drawn to represent the RayCast3D. Requires Visible Collision Shapes to be enabled in the Debug menu for the debug shape to be visible at run-time.

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

If true, collisions will be reported.

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

If true, this raycast will not report collisions with its parent node. This property only has an effect if the parent node is a CollisionObject3D. See also Entity.GetParent and RayCast3D.AddException.

HitBackFacesProperty
# HitBackFaces
C#
public bool HitBackFaces { get; set; }

If true, the ray will hit back faces with concave polygon shapes with back face enabled or heightmap shapes.

HitFromInsideProperty
# HitFromInside
C#
public bool HitFromInside { get; set; }

If true, the ray will detect a hit when starting inside shapes. In this case the collision normal will be Vector3(0, 0, 0). Does not affect shapes with no volume like concave polygon or heightmap.

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

The segment endpoint local to the RayCast. DirectSpaceState.From/To instead use world coordinates; transform with ToGlobal when comparing them.

Methods35

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

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

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

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

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

Removes all collision exceptions for this ray.

ForceRaycastUpdatevoid
# ForceRaycastUpdate
C#
public void ForceRaycastUpdate();

Updates the query result immediately, including when Enabled = false. It does not advance all physics or replace correct world/access-phase selection.

GetColliderReckfellObject
# GetCollider
C#
public ReckfellObject GetCollider();

Returns the first object that the ray intersects, or null if no object is intersecting the ray (i.e. RayCast3D.IsColliding returns false). Note: This object is not guaranteed to be a CollisionObject3D. For example, if the ray intersects a CsgShape3D or a GridMap, the method will return a CsgShape3D or GridMap instance.

Returns ReckfellObject
GetColliderRidRid
# GetColliderRid
C#
public Rid GetColliderRid();

Returns the Rid of the first object that the ray intersects, or an empty Rid if no object is intersecting the ray (i.e. RayCast3D.IsColliding returns false).

Returns Rid
GetColliderShapeint
# GetColliderShape
C#
public int GetColliderShape();

Returns the shape ID of the first object that the ray intersects, or 0 if no object is intersecting the ray (i.e. RayCast3D.IsColliding returns false). To get the intersected shape node, for a CollisionObject3D target, use:

C#
var target = (CollisionObject3D)GetCollider(); // A CollisionObject3D.
var shapeId = GetColliderShape(); // The shape index in the collider.
var ownerId = target.ShapeFindOwner(shapeId); // The owner ID in the collider.
var shape = target.ShapeOwnerGetOwner(ownerId);
Returns int
GetCollisionFaceIndexint
# GetCollisionFaceIndex
C#
public int GetCollisionFaceIndex();

Returns the collision object's face index at the collision point, or -1 if the shape intersecting the ray is not a ConcavePolygonShape3D.

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 RayCast3D.CollisionMask is enabled, given a layer_number between 1 and 32.

Parameters
NameTypeDefault
layerNumberint—
Returns bool
GetCollisionNormalVector3
# GetCollisionNormal
C#
public Vector3 GetCollisionNormal();

Returns the normal of the intersecting object's shape at the collision point, or Vector3(0, 0, 0) if the ray starts inside the shape and RayCast3D.HitFromInside is true. Note: Check that RayCast3D.IsColliding returns true before calling this method to ensure the returned normal is valid and up-to-date.

Returns Vector3
GetCollisionPointVector3
# GetCollisionPoint
C#
public Vector3 GetCollisionPoint();

Returns the collision point at which the ray intersects the closest object, in the global coordinate system. If RayCast3D.HitFromInside is true and the ray starts inside of a collision shape, this function will return the origin point of the ray. Note: Check that RayCast3D.IsColliding returns true before calling this method to ensure the returned point is valid and up-to-date.

Returns Vector3
GetDebugShapeCustomColorColor
# GetDebugShapeCustomColor
C#
public Color GetDebugShapeCustomColor();
Returns Color
GetDebugShapeThicknessint
# GetDebugShapeThickness
C#
public int GetDebugShapeThickness();
Returns int
GetExcludeParentBodybool
# GetExcludeParentBody
C#
public bool GetExcludeParentBody();
Returns bool
GetTargetPositionVector3
# GetTargetPosition
C#
public Vector3 GetTargetPosition();
Returns Vector3
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 ray's vector (considering the vector length).

Returns bool
IsEnabledbool
# IsEnabled
C#
public bool IsEnabled();
Returns bool
IsHitBackFacesEnabledbool
# IsHitBackFacesEnabled
C#
public bool IsHitBackFacesEnabled();
Returns bool
IsHitFromInsideEnabledbool
# IsHitFromInsideEnabled
C#
public bool IsHitFromInsideEnabled();
Returns bool
RemoveExceptionvoid
# RemoveException
C#
public void RemoveException(CollisionObject3D node);

Removes a collision exception so the ray can report collisions with the specified node.

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

Removes a collision exception so the ray can 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 RayCast3D.CollisionMask, given a layer_number between 1 and 32.

Parameters
NameTypeDefault
layerNumberint—
valuebool—
SetDebugShapeCustomColorvoid
# SetDebugShapeCustomColor
C#
public void SetDebugShapeCustomColor(Color debugShapeCustomColor);
Parameters
NameTypeDefault
debugShapeCustomColorColor—
SetDebugShapeThicknessvoid
# SetDebugShapeThickness
C#
public void SetDebugShapeThickness(int debugShapeThickness);
Parameters
NameTypeDefault
debugShapeThicknessint—
SetEnabledvoid
# SetEnabled
C#
public void SetEnabled(bool enabled);
Parameters
NameTypeDefault
enabledbool—
SetExcludeParentBodyvoid
# SetExcludeParentBody
C#
public void SetExcludeParentBody(bool mask);
Parameters
NameTypeDefault
maskbool—
SetHitBackFacesvoid
# SetHitBackFaces
C#
public void SetHitBackFaces(bool enable);
Parameters
NameTypeDefault
enablebool—
SetHitFromInsidevoid
# SetHitFromInside
C#
public void SetHitFromInside(bool enable);
Parameters
NameTypeDefault
enablebool—
SetTargetPositionvoid
# SetTargetPosition
C#
public void SetTargetPosition(Vector3 localPoint);
Parameters
NameTypeDefault
localPointVector3—
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.