natiny.physics.raycast

Lua
natiny.physics.raycast(ox, oy, oz, dx, dy, dz [, max_distance]) -> hit

Finds the first body along a ray.

Parameters

Name Type Default Description
ox, oy, oz number Where the ray starts, world space
dx, dy, dz number Which way it points; need not be normalized
max_distance number 1000 How far to look, in metres

Returns

Type Description
table or nil The hit, or nil when the ray reached max_distance without touching anything

The table has body, the hit point x, y, z, the surface normal nx, ny, nz, and distance along the ray.

Example

Lua
local hit = natiny.physics.raycast(px, py, pz, 0, -1, 0, 2)