physics.space.raycast

Client

Casts a ray through the physics world and returns the first collision encountered, if any


Syntax

local hit = physics.space.raycast(
    from,
    to,
    options = {}
)

Parameters

TypeNameDescription
vector3fromWorld-space start position of the ray as {x, y, z}
vector3toWorld-space end position of the ray as {x, y, z}
tableoptionsOptional table with mask, exclude, collide_bodies, collide_areas, hit_from_inside, and hit_back_faces fields

Returns

TypeNameDescription
tablehitTable with position, normal, and collider fields, or false if nothing was hit

Examples

Raycast forward from a position
local hit = physics.space.raycast({0, 2, 0}, {0, 2, -10}, {
    mask = 1,
    collide_bodies = true
})

if hit then
    core.engine.print("info", hit.position)
end

On this page