Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/tiny-engine/llms.txt
Use this file to discover all available pages before exploring further.
RayCast projects an infinitely thin line from its world-space position in the direction of direction (a relative endpoint vector) and reports the first Collider it intersects whose groups match collidesWith. Unlike the spatial-hash-based broad phase used by Collider, raycasts query the collision system’s registered collider list directly, checking intersection geometry on every frame.
RayCast extends Node2D, so its origin is determined by its world-space position, which inherits from any parent Transform nodes.
Usage
Props
The relative endpoint of the ray from its origin. The ray starts at the node’s world-space
position and ends at position + direction. A Vector2(200, 0) casts 200 pixels to the right. Reactive when a SignalGetter is passed.The collider groups this ray checks against. Only colliders whose
group set contains at least one of these strings will be detected. Converted to a deduplicated array at construction — immutable afterwards.Local position offset for the ray’s origin. Defaults to
Vector2.ZERO, meaning the ray starts at the parent transform’s position.A ref created by
useRefNode(PrimaryNode.RayCast). Use it to call getCollider() at any time and inspect the currently detected collider.Optional node identifier. Must match
[a-zA-Z][a-zA-Z0-9-_]* when a string.Draw order among siblings. Defaults to
0.Events
Subscribe withuseEvent. Events fire on both the RayCast node and the detected Collider node.
| Event name | Callback signature | Description |
|---|---|---|
colliderEntered | (collider: Collider) => void | Fires on the frame the ray first intersects a collider. |
colliderExited | (collider: Collider) => void | Fires on the frame the ray no longer intersects the previous collider. |
started | () => void | Fires once after the node registers with the collision system. |
updated | (delta: number) => void | Fires every frame during the update cycle. |
drawed | (delta: number) => void | Fires every frame during the draw cycle. |
destroyed | () => void | Fires once when the node is removed. |
colliderEntered and colliderExited emit on both the RayCast node and the affected Collider node. You can listen on either side depending on which component owns the logic.Runtime methods and properties
| Member | Type / Signature | Description |
|---|---|---|
getCollider() | () => Collider | null | Returns the currently detected collider, or null if the ray is clear. |
direction | Vector2 | Read/write. The relative ray endpoint. Modifying this updates the ray’s direction next frame. |
collidesWith | string[] | Read-only. The groups this ray detects. |
length | number | Read-only. Euclidean length of the direction vector. |
Debug visualisation
SettestOptions.showRayCasts = true to draw rays as red lines with arrowheads during development.
Complete example — enemy with line-of-sight attack
Example — polling getCollider() imperatively
You can also poll the current collider without subscribing to events:
Related
- Collision guide — how the collision system works, spatial hashing, and groups
Collider— area-based overlap detectionTransform— parent node that sets the ray’s world-space originuseRefNode— obtain a ref to callgetCollider()imperativelyuseEvent— subscribe tocolliderEnteredandcolliderExited