physics.space.raycast
Client
Casts a ray through the physics world and returns the first collision encountered, if any
Syntax
local hit = physics.space.raycast(
from,
to,
options = {}
)Parameters
| Type | Name | Description |
|---|---|---|
vector3 | from | World-space start position of the ray as {x, y, z} |
vector3 | to | World-space end position of the ray as {x, y, z} |
table | options | Optional table with mask, exclude, collide_bodies, collide_areas, hit_from_inside, and hit_back_faces fields |
Returns
| Type | Name | Description |
|---|---|---|
table | hit | Table with position, normal, and collider fields, or false if nothing was hit |
Examples
local hit = physics.space.raycast({0, 2, 0}, {0, 2, -10}, {
mask = 1,
collide_bodies = true
})
if hit then
core.engine.print("info", hit.position)
end