World:raycast
EditCasts a ray through the World, calling a function every time the ray intersects with a Shape.
Arguments
Name | Type | Description |
x1 | number | The x coordinate of the starting position of the ray. |
y1 | number | The y coordinate of the starting position of the ray. |
z1 | number | The z coordinate of the starting position of the ray. |
x2 | number | The x coordinate of the ending position of the ray. |
y2 | number | The y coordinate of the ending position of the ray. |
z2 | number | The z coordinate of the ending position of the ray. |
callback | function | The function to call when an intersection is detected. |
Returns
Nothing
Arguments
Name | Type | Description |
start | Vec3 | The starting position of the ray. |
end | Vec3 | The end position of the ray. |
callback | function | The function to call when an intersection is detected. |
Returns
Nothing
Notes
The callback is passed the shape that was hit, the hit position (in world coordinates), and the normal vector of the hit.
Example
function lovr.load()
world = lovr.physics.newWorld()
world:newSphereCollider(0, 0, 0, 2)
-- Cast a ray through the sphere
local x1, y1, z1 = .5, 3, 0
local x2, y2, z2 = -.5, -2, 0
world:raycast(x1, y1, z1, x2, y2, z2, function(shape, x, y, z, nx, ny, nz)
print('Collision detected!', shape, x, y, z, nx, ny, nz)
end)
end