Glorpia Docs
Scripting / Workspace method

workspace:Raycast()

Casts a ray through the physics world and returns the first hit.

Syntax

workspace:Raycast(origin, direction)

Parameters

NameTypeDescription
originVector3World-space ray start position.
directionVector3Direction and maximum distance. Its magnitude becomes the cast length.

Return value

NameTypeDescription
PositionVector3World-space hit point.
NormalVector3Surface normal at the hit.
DistancenumberDistance from origin to the hit.
InstanceInstance?Hit Glorpia instance when the collider maps to one.
Returns nil when the direction is effectively zero or the ray does not hit anything.

Example: Cast Downward

Luau
local origin = Vector3.new(0, 20, 0)
local direction = Vector3.new(0, -50, 0)
local hit = workspace:Raycast(origin, direction)

if hit then
    print("Hit", hit.Instance, "at", hit.Position)
    print("Distance", hit.Distance)
end