self:move_and_collide

Client

Moves the rigid body by a motion vector, stopping and reporting the first collision encountered along the way


Syntax

local collision = self:move_and_collide(
    motion,
    test_only = false
)

Parameters

TypeNameDescription
vector3motionMotion vector to move by as {x, y, z}
booltest_onlyIf true, only tests the motion without actually moving the body

Returns

TypeNameDescription
tablecollisionTable with position, normal, travel, remainder, and depth fields, or false if no collision occurred

Examples

Move a rigid body and detect collisions
local entity = physics.rigid.create()

local collision = entity:move_and_collide({0, 0, -1})
if collision then
    core.engine.print("info", collision.normal)
end

On this page