Skip to content

API - World

Access to information about the space.

When extending BasePlugin, these functions can be accessed via this.world.*

When extending BaseComponent, these functions can be accessed via this.plugin.world.*

Functions

getID() : string

Returns the unique ID of this space.

getInstanceID() : string

Returns the server instance ID.

getSessionID() : string

Returns a unique ID for the session.

raycast(options={}) : object[]

Performs a raycast and returns the properties of the objects that were hit.

Properties available for the options parameter

Property Type Description Example
screenPosition Vector2 Determines the screen co-ordinate at which the ray will be cast. Top-left of the screen is { x: 0, y: 0 } and bottom-right of the screen is { x: 1, y: 1 } { x: 0.5, y: 0.5 }
worldPosition Vector3 Determines the world position at which the ray will be cast { x: 12, y: 1.4, z: 15.6 }
worldDirection Vector3 Normalized direction at which to cast the ray. Ignored when screenPosition has been given { x: 0, y: 1, z: 0 }
length number Length of the ray in metres. Defaults to Number.POSITIVE_INFINITY 21
collision boolean true to only hit items with collision enabled, false otherwise. Defaults to false false

Below is an example of the return value

const hitObjects = this.world.raycast()
console.log(hitObjects)
// [
//   {
//     id: <string>,
//     distance: <number>,
//     point: { x: <number>, y: <number>, z: <number> },
//     faceNormal: { x: <number>, y: <number>, z: <number> },
//     faceNormalAdjusted: { x: <number>, y: <number>, z: <number> },
//     quaternionAdjusted: { x: <number>, y: <number>, z: <number>, w: <number> }
//     wallProps: {
//       x: <number>,
//       y: <number>,
//       height: <number>,
//       quatX: <number>,
//       quatY: <number>,
//       quatZ: <number>,
//       quatW: <number>,
//       rotation: <number>,
//       rotation_x: <number>,
//       rotation_y: <number>,
//       rotation_z: <number>,
//       rotation_axes_x: <boolean>,
//       rotation_axes_y: <boolean>,
//       rotation_axes_z: <boolean>,
//       rotation_speed: <number>
//     }
//   },
//   ...
// ]
Back to top