Skip to content
M2O Scripting APIScripting reference
Global objectClient APIGenerated

Camera

const Camera: object

Defined in: client/api.d.ts:1096

Client control of the local game camera: projecting world positions through it, reading and overriding its lens, shaking it, and driving a scripted view on its own camera layer.

getAnchor(): number

Returns the network id of the entity the scripted camera’s eye is anchored to.

number

The entity’s network id, or 0 when no anchor is set.

getClip(): CameraClip | null

Reads the camera’s current clip distances.

CameraClip | null

The clip distances, or null when no camera is up.

getFieldOfView(): number

Returns the horizontal field of view in degrees: the held override when there is one, otherwise the camera’s live value.

number

getMatrix(): CameraMatrix | null

Reads the live camera view, whether it is the gameplay camera or a scripted one.

CameraMatrix | null

The current view, or null when no camera is up.

const view = Camera.getMatrix();
if (view) {
// view.position, view.target and view.up are world-space; view.fieldOfView is in degrees.
}

getTarget(): number

Returns the network id of the entity the scripted camera is looking at.

number

The entity’s network id, or 0 when no target is set.

interpolate(x, y, z, lookX, lookY, lookZ, durationSeconds): void

Smoothly moves the camera from its current view to a fixed destination until reset is called.

number

Destination camera world-space X coordinate.

number

Destination camera world-space Y coordinate.

number

Destination camera world-space Z coordinate.

number

Destination world-space look-at X coordinate.

number

Destination world-space look-at Y coordinate.

number

Destination world-space look-at Z coordinate.

number

Transition duration in seconds; zero or less cuts.

void

isScripted(): boolean

Checks whether a scripted camera view is currently held.

boolean

True while setPosition or interpolate owns the camera.

raycastFromScreen(x, y, maxDistance?, options?): RaycastHit | null

Casts a ray from the active camera through a display pixel and returns the closest physics surface it hits, the inverse of worldToScreen. Use the screen centre for what the player is looking at, or the cursor position for picking.

number

Display pixel X coordinate.

number

Display pixel Y coordinate.

number

How far to cast, in metres; defaults to 1000.

RaycastOptions

Optional filters.

RaycastHit | null

The closest hit, or null when nothing was hit or no camera is up.

const hit = Camera.raycastFromScreen(cursorX, cursorY);
if (hit && hit.entity) {
// hit.entity is the Player or Vehicle under the cursor.
}

reset(): void

Returns control to the normal gameplay camera and clears any follow target. Field of view and clip overrides are left alone.

void

resetClip(): void

Restores the clip distances the camera booted with.

void

resetFieldOfView(): void

Drops the field of view override and lets the camera mode drive it again.

void

setAnchor(target, offsetX?, offsetY?, offsetZ?): void

Moves the scripted camera’s eye with a streamed entity. Combine with setTarget for a chase camera. Only has an effect while a scripted view is held.

number | Vehicle | Player | null

The entity to hang the camera off, its network id, or null to release.

number

Local-space X offset from the entity; defaults to zero.

number

Local-space Y offset from the entity; defaults to zero.

number

Local-space Z offset from the entity; defaults to zero.

void

setClip(nearDistance, farDistance): boolean

Sets the camera’s clip planes. The engine only rewrites these when it builds or resets a camera, so one call holds until the world reloads.

number

Near clip distance in metres; at least 0.001.

number

Far clip distance in metres; at least 0.01 beyond the near plane.

boolean

True when the distances were accepted.

setFieldOfView(degrees): boolean

Holds the camera’s field of view, overriding whatever the active camera mode asks for. Applies to the gameplay camera too.

number

Horizontal field of view, above 0 and below 180.

boolean

True when the value was accepted.

setPosition(x, y, z, lookX, lookY, lookZ): void

Cuts the camera to a fixed position and look-at target until reset is called. Streaming stays pinned to the player while a scripted view is active.

number

Camera world-space X coordinate.

number

Camera world-space Y coordinate.

number

Camera world-space Z coordinate.

number

World-space X coordinate the camera looks at.

number

World-space Y coordinate the camera looks at.

number

World-space Z coordinate the camera looks at.

void

setTarget(target, offsetX?, offsetY?, offsetZ?): void

Keeps the scripted camera aimed at a streamed entity as it moves; the look-at point is re-evaluated every frame. Only has an effect while a scripted view is held.

number | Vehicle | Player | null

The entity to look at, its network id, or null to release.

number

Local-space X offset from the entity; defaults to zero.

number

Local-space Y offset from the entity; defaults to zero.

number

Local-space Z offset from the entity; defaults to zero.

void

Camera.setPosition(10, 20, 5, 0, 0, 0);
Camera.setTarget(LocalPlayer, 0, 0, 1);

shake(angleDegrees, durationSeconds?, frequency?): boolean

Shakes whichever camera is live - on foot, in a car or scripted. The shake decays on its own.

number

Peak camera rotation, i.e. how hard the shake hits.

number

How long the shake takes to decay to nothing; defaults to 1.

number

Oscillation rate; defaults to 10, which is what the engine’s own shake runs at.

boolean

True when a camera was there to shake.

Camera.shake(3, 0.6);

stopShake(): boolean

Cancels a running shake.

boolean

True when a camera was there to cancel it on.

worldToScreen(x, y, z): ScreenPosition

Projects a world-space position to display pixel coordinates.

number

World X coordinate.

number

World Y coordinate.

number

World Z coordinate.

ScreenPosition

Screen coordinates and whether the point is visible through the active camera.

const point = Camera.worldToScreen(10, 20, 5);
if (point.visible) {
// point.x and point.y are display pixels.
}