Skip to content
KCKingdoms Connected Scripting APIScripting guides and API
Global objectClient APIGenerated

World

const World: 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.

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.

Vector3

The centre of the sphere, in world-space metres.

number

Its radius in metres, up to 256.

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.

string

number

boolean

WorldNearbyEntity[]

The entities inside it, nearest first.

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.

Vector3

The point to look under, in world-space metres. Its own z is where the probe is centred.

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

number | null

The world-space z of what is underfoot, or null when the probe reached nothing within its range.

raycast(from, to, options?): WorldRayHit | null

Traces a segment through the world and reports the first thing it meets.

Vector3

Where the ray starts, in world-space metres.

Vector3

Where it ends. Up to 4096 metres away; a ray of no length is refused.

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.

boolean

"cover" | "anything" | "ground"

WorldRayHit | null

What it hit, or null when the ray met nothing and when this machine has no world loaded.

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.

Vector3

Where the ray starts, in world-space metres.

Vector3

Where it ends. Up to 4096 metres away; a ray of no length is refused.

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.

boolean

number

"cover" | "anything" | "ground"

WorldRayHit[]

What the ray met, nearest first; empty when it met nothing and when this machine has no world loaded.

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.

Vector3

The point to look under, in world-space metres.

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

WorldRayHit | null

What is underfoot, or null when the probe reached nothing.