natiny.physics.raycast
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
local hit = natiny.physics.raycast(px, py, pz, 0, -1, 0, 2)
Notes
- The nearest hit, not the first one found.
- A zero-length direction or a
max_distanceof zero or less returnsnil. - The normal points out of the surface that was hit.
- Static bodies answer immediately; nothing has to have been stepped first.