class Raycast
package fivem.client.core
Shape tests — the game's ray casting, used for "what am I looking at?" interaction, ground probing and line-of-sight checks.
var hit = Raycast.fromCamera(10.0);
if (hit.hit && hit.entity != null) {
Ui.showHelp("Press ~INPUT_CONTEXT~ to interact");
}
The asynchronous natives take a frame or two to produce a result, so the methods here use the synchronous variant: it returns this frame, which is what interaction code needs. That costs more per call — don't run one every frame at long range if a distance check would do.
Static methods
staticbetween(from:Vector3, to:Vector3, flags:RaycastFlags = Everything, ?ignore:Entity):RaycastHit
Casts a ray between two points.
Parameters:
ignore | An entity to pass through — usually the player, so the ray doesn't immediately hit their own body. |
|---|
staticinlinedirection(origin:Vector3, direction:Vector3, distance:Float, flags:RaycastFlags = Everything, ?ignore:Entity):RaycastHit
Casts a ray from a point along a direction for distance metres.
staticinlinedown(position:Vector3, distance:Float = 10.0, flags:RaycastFlags = Everything, ?ignore:Entity):RaycastHit
Casts a ray straight down from position to find the surface beneath
it — more reliable than World.groundZ on top of vehicles, props and
other non-terrain surfaces.
staticfromCamera(distance:Float = 10.0, flags:RaycastFlags = Everything):RaycastHit
Casts a ray from the gameplay camera along its view direction — what the player is looking at.
The local player is excluded automatically, since a ray starting at the camera would otherwise hit their own head in first person.