reckfellENGINE

RayCast2D

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

On this page
class RayCast2DReckfellSharpInherits Entity2D

RayCast2D 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

RayCast2DConstructor
# RayCast2D
C#
public RayCast2D();

Properties7

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 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.

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 CollisionObject2D. See also Entity.GetParent and RayCast2D.AddException.

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 Vector2(0, 0). Does not affect concave polygon shapes.

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

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

Methods28

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

Adds a collision exception so the ray 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 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. RayCast2D.IsColliding returns false). Note: This object is not guaranteed to be a CollisionObject2D. For example, if the ray intersects a TileMapLayer, the method will return a TileMapLayer 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. RayCast2D.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. RayCast2D.IsColliding returns false). To get the intersected shape node, for a CollisionObject2D target, use:

C#
var target = (CollisionObject2D)GetCollider(); // A CollisionObject2D.
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
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 RayCast2D.CollisionMask is enabled, given a layer_number between 1 and 32.

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

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

Returns Vector2
GetCollisionPointVector2
# GetCollisionPoint
C#
public Vector2 GetCollisionPoint();

Returns the collision point at which the ray intersects the closest object, in the global coordinate system. If RayCast2D.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 RayCast2D.IsColliding returns true before calling this method to ensure the returned point is valid and up-to-date.

Returns Vector2
GetExcludeParentBodybool
# GetExcludeParentBody
C#
public bool GetExcludeParentBody();
Returns bool
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 ray's vector (considering the vector length).

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

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

Parameters
NameTypeDefault
nodeCollisionObject2D—
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 RayCast2D.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—
SetHitFromInsidevoid
# SetHitFromInside
C#
public void SetHitFromInside(bool enable);
Parameters
NameTypeDefault
enablebool—
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.