Skip to content

RayCast

The nearest surface along a line.

Shoots a ray from one point to the other through the level’s static geometry and answers with the first surface it meets: where, which way it faces, how far along, the engine’s material id of a mesh triangle (0 for the primitives), and - when the surface belongs to a game entity (a door, a chest, a ladder) - the entity’s class and name. Players, actors and horses are not in the geometry; the doors the server’s records say are open are let through.

RayCast(x1, y1, z1, x2, y2, z2)
Parameter Type
x1 number metres, the start
y1 number metres
z1 number metres
x2 number metres, the end
y2 number metres
z2 number metres

a table {x, y, z, nx, ny, nz, distance, material, class, name} - the point, the normal, the metres along the line, the material, the owning entity’s class and name (empty strings for the level’s own geometry); nil when nothing is in the way, or without the geometry

local hit = RayCast(px, py, pz + 1.5, px + 20 * dx, py + 20 * dy, pz + 1.5)
if hit then SendClientMessage(pid, COLOUR_SERVER, string.format("a wall %.1f m ahead", hit.distance)) end

IsLineOfSight · GetGroundZ · HasCollision · the The world - clock, weather, terrain, the navmesh, the geometry group of the index