World
constWorld:object
Defined in: client/api.d.ts:1766
What this machine’s engine can be asked about the level around it: what a trace meets, what the ground is under a point, and which entities are inside a sphere.
Each is the engine’s own query rather than a search over everything loaded, so the cost is what the question covers. They answer inside the call, because this is the machine that has the world – the server’s World asks the same three questions as promises, because it has to borrow a client’s world to answer them.
None of it is replicated and none of it is authority: an answer describes what one client has streamed in at one moment. A zone that matters is decided on the server, from an answer the server asked for itself.
Type Declaration
Section titled “Type Declaration”entitiesInRadius()
Section titled “entitiesInRadius()”entitiesInRadius(
centre,radius,options?):WorldNearbyEntity[]
Every entity the engine has inside a sphere, nearest first.
This reads the engine’s own spatial grid, so it costs what the sphere covers rather than what the level holds – but it only sees what this client has streamed in, which for a distant point is nothing.
Parameters
Section titled “Parameters”centre
Section titled “centre”The centre of the sphere, in world-space metres.
radius
Section titled “radius”number
Its radius in metres, up to 256.
options?
Section titled “options?”class reports only entities of that engine class – AnimDoor, NPC_NAI, GeomEntity – and a class the engine does not know matches nothing rather than everything; omitted, every class is reported. max is how many to report, nearest first, up to 64. physicalOnly skips entities the engine has built no physics for, which is the filter the game’s own proximity query applies, and is off by default.
class?
Section titled “class?”string
number
physicalOnly?
Section titled “physicalOnly?”boolean
Returns
Section titled “Returns”The entities inside it, nearest first.
getGroundZ()
Section titled “getGroundZ()”getGroundZ(
position,options?):number|null
The height of the ground under a point.
A trace rather than a terrain height, so it stands on whatever is actually there – a bridge, a floor, a castle roof – and not on the heightmap underneath it.
Parameters
Section titled “Parameters”position
Section titled “position”The point to look under, in world-space metres. Its own z is where the probe is centred.
options?
Section titled “options?”How far above the point the probe starts and how far below it reaches, in metres. 5 and 200 by default – the 5 above is what lets a point already slightly underground still resolve – and up to 512 each.
number
number
Returns
Section titled “Returns”number | null
The world-space z of what is underfoot, or null when the probe reached nothing within its range.
raycast()
Section titled “raycast()”raycast(
from,to,options?):WorldRayHit|null
Traces a segment through the world and reports the first thing it meets.
Parameters
Section titled “Parameters”Where the ray starts, in world-space metres.
Where it ends. Up to 4096 metres away; a ray of no length is refused.
options?
Section titled “options?”mode picks which of the game’s own three traces to run: cover asks whether the world is in the way – static geometry, props and doors block, and bodies cannot, which is what a line of sight wants; anything asks what is under the ray, bodies included, which is what a pick wants; ground sees only surfaces a player could stand on. It defaults to cover, and a name that is none of the three is rejected rather than guessed at.
ignoreSelf passes the local player’s own body through, and is on by default: the player stands where the camera does, so a trace from the camera would otherwise mostly hit them. Both of a body’s colliders are skipped, not just the entity’s.
ignoreSelf?
Section titled “ignoreSelf?”boolean
"cover" | "anything" | "ground"
Returns
Section titled “Returns”WorldRayHit | null
What it hit, or null when the ray met nothing and when this machine has no world loaded.
raycastAll()
Section titled “raycastAll()”raycastAll(
from,to,options?):WorldRayHit[]
Traces a segment and reports everything solid along it, nearest first. Each hit is found by re-tracing past the one before, so a window does not hide the wall it is set in.
Parameters
Section titled “Parameters”Where the ray starts, in world-space metres.
Where it ends. Up to 4096 metres away; a ray of no length is refused.
options?
Section titled “options?”mode and ignoreSelf are as World.raycast documents them. maxHits is how many things along the ray to report, up to 8 and 8 by default.
ignoreSelf?
Section titled “ignoreSelf?”boolean
maxHits?
Section titled “maxHits?”number
"cover" | "anything" | "ground"
Returns
Section titled “Returns”What the ray met, nearest first; empty when it met nothing and when this machine has no world loaded.
resolveGround()
Section titled “resolveGround()”resolveGround(
position,options?):WorldRayHit|null
The same probe as getGroundZ, with everything it found rather than only the height: the slope it landed on, and what the surface is made of.
Parameters
Section titled “Parameters”position
Section titled “position”The point to look under, in world-space metres.
options?
Section titled “options?”How far above the point the probe starts and how far below it reaches, in metres. 5 and 200 by default – the 5 above is what lets a point already slightly underground still resolve – and up to 512 each.
number
number
Returns
Section titled “Returns”WorldRayHit | null
What is underfoot, or null when the probe reached nothing.