physics.space.cast_motion

Client

Predicts how far a shape could travel along a motion vector before colliding, without actually moving anything


Syntax

local motion_result = physics.space.cast_motion(
    shape,
    position,
    motion,
    options = {}
)

Parameters

TypeNameDescription
tableshapeShape descriptor table: {type = "box"/"sphere"/"capsule"/"cylinder", ...} with shape-specific fields such as size, radius, or height
vector3positionWorld-space starting position of the shape as {x, y, z}
vector3motionMotion vector to test as {x, y, z}
tableoptionsOptional table with mask, exclude, collide_bodies, and collide_areas fields

Returns

TypeNameDescription
tablemotion_resultTable with safe and unsafe fractions of the motion that can be traveled, or false if the query failed

Examples

Predict a capsule's movement
local motion_result = physics.space.cast_motion(
    { type = "capsule", radius = 0.4, height = 1.8 },
    position, {0, 0, -2}
)

core.engine.print("info", motion_result.safe)

On this page