Engine.physics
Functions
Engine.physics.castRay
local result = Engine.physics.castRay(origin, delta, flags, excludedObjectHandle)
Casts a ray from origin to origin + delta and returns the first hit, or nil when nothing
is hit.
| Parameter |
Type |
Description |
origin |
Point3d |
Start of the ray, or a table with x, y and z. |
delta |
Vector3d |
Full length and direction of the ray, not a unit vector. A table with i, j and k also works. |
flags |
string, optional |
What the ray hits. See below. Default is "environment". |
excludedObjectHandle |
ObjectHandle, optional |
Object the ray passes through, such as the unit casting it. |
| Flags |
Hits |
"environment" |
The level and water. |
"lineOfSight" |
What blocks vision: the level, vehicles, scenery and machines. |
"projectiles" |
What stops a projectile: the level, water and every object. |
"objects" |
Every object, but not the level. |
"bipedMovement" |
What blocks a walking biped: the level, vehicles, scenery and machines. |
"bipedMovementSolid" |
Like "bipedMovement", and bipeds too. |
"deadBipedMovement" |
What blocks a dead biped: the level, scenery and machines. |
"vehicleMovement" |
What blocks a vehicle: the level, scenery and machines. |
The result is a CollisionResult:
| Field |
Type |
Description |
point |
Point3d |
Where the ray hit. |
type |
string |
"structure", "media" (water) or "object". |
objectHandle |
ObjectHandle or nil |
The object hit, when type is "object". |
Example
-- Find the ground below a point.
local hit = Engine.physics.castRay({x = 10, y = 20, z = 50}, {i = 0, j = 0, k = -100})
if hit then
Balltze.logger.info("Ground at z = {}", hit.point.z)
end