Camera
constCamera: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.
Type Declaration
Section titled “Type Declaration”getAnchor()
Section titled “getAnchor()”getAnchor():
number
Returns the network id of the entity the scripted camera’s eye is anchored to.
Returns
Section titled “Returns”number
The entity’s network id, or 0 when no anchor is set.
getClip()
Section titled “getClip()”getClip():
CameraClip|null
Reads the camera’s current clip distances.
Returns
Section titled “Returns”CameraClip | null
The clip distances, or null when no camera is up.
getFieldOfView()
Section titled “getFieldOfView()”getFieldOfView():
number
Returns the horizontal field of view in degrees: the held override when there is one, otherwise the camera’s live value.
Returns
Section titled “Returns”number
getMatrix()
Section titled “getMatrix()”getMatrix():
CameraMatrix|null
Reads the live camera view, whether it is the gameplay camera or a scripted one.
Returns
Section titled “Returns”CameraMatrix | null
The current view, or null when no camera is up.
Example
Section titled “Example”const view = Camera.getMatrix();if (view) { // view.position, view.target and view.up are world-space; view.fieldOfView is in degrees.}getTarget()
Section titled “getTarget()”getTarget():
number
Returns the network id of the entity the scripted camera is looking at.
Returns
Section titled “Returns”number
The entity’s network id, or 0 when no target is set.
interpolate()
Section titled “interpolate()”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.
Parameters
Section titled “Parameters”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.
durationSeconds
Section titled “durationSeconds”number
Transition duration in seconds; zero or less cuts.
Returns
Section titled “Returns”void
isScripted()
Section titled “isScripted()”isScripted():
boolean
Checks whether a scripted camera view is currently held.
Returns
Section titled “Returns”boolean
True while setPosition or interpolate owns the camera.
raycastFromScreen()
Section titled “raycastFromScreen()”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.
Parameters
Section titled “Parameters”number
Display pixel X coordinate.
number
Display pixel Y coordinate.
maxDistance?
Section titled “maxDistance?”number
How far to cast, in metres; defaults to 1000.
options?
Section titled “options?”Optional filters.
Returns
Section titled “Returns”RaycastHit | null
The closest hit, or null when nothing was hit or no camera is up.
Example
Section titled “Example”const hit = Camera.raycastFromScreen(cursorX, cursorY);if (hit && hit.entity) { // hit.entity is the Player or Vehicle under the cursor.}reset()
Section titled “reset()”reset():
void
Returns control to the normal gameplay camera and clears any follow target. Field of view and clip overrides are left alone.
Returns
Section titled “Returns”void
resetClip()
Section titled “resetClip()”resetClip():
void
Restores the clip distances the camera booted with.
Returns
Section titled “Returns”void
resetFieldOfView()
Section titled “resetFieldOfView()”resetFieldOfView():
void
Drops the field of view override and lets the camera mode drive it again.
Returns
Section titled “Returns”void
setAnchor()
Section titled “setAnchor()”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.
Parameters
Section titled “Parameters”target
Section titled “target”number | Vehicle | Player | null
The entity to hang the camera off, its network id, or null to release.
offsetX?
Section titled “offsetX?”number
Local-space X offset from the entity; defaults to zero.
offsetY?
Section titled “offsetY?”number
Local-space Y offset from the entity; defaults to zero.
offsetZ?
Section titled “offsetZ?”number
Local-space Z offset from the entity; defaults to zero.
Returns
Section titled “Returns”void
setClip()
Section titled “setClip()”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.
Parameters
Section titled “Parameters”nearDistance
Section titled “nearDistance”number
Near clip distance in metres; at least 0.001.
farDistance
Section titled “farDistance”number
Far clip distance in metres; at least 0.01 beyond the near plane.
Returns
Section titled “Returns”boolean
True when the distances were accepted.
setFieldOfView()
Section titled “setFieldOfView()”setFieldOfView(
degrees):boolean
Holds the camera’s field of view, overriding whatever the active camera mode asks for. Applies to the gameplay camera too.
Parameters
Section titled “Parameters”degrees
Section titled “degrees”number
Horizontal field of view, above 0 and below 180.
Returns
Section titled “Returns”boolean
True when the value was accepted.
setPosition()
Section titled “setPosition()”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.
Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”void
setTarget()
Section titled “setTarget()”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.
Parameters
Section titled “Parameters”target
Section titled “target”number | Vehicle | Player | null
The entity to look at, its network id, or null to release.
offsetX?
Section titled “offsetX?”number
Local-space X offset from the entity; defaults to zero.
offsetY?
Section titled “offsetY?”number
Local-space Y offset from the entity; defaults to zero.
offsetZ?
Section titled “offsetZ?”number
Local-space Z offset from the entity; defaults to zero.
Returns
Section titled “Returns”void
Example
Section titled “Example”Camera.setPosition(10, 20, 5, 0, 0, 0);Camera.setTarget(LocalPlayer, 0, 0, 1);shake()
Section titled “shake()”shake(
angleDegrees,durationSeconds?,frequency?):boolean
Shakes whichever camera is live - on foot, in a car or scripted. The shake decays on its own.
Parameters
Section titled “Parameters”angleDegrees
Section titled “angleDegrees”number
Peak camera rotation, i.e. how hard the shake hits.
durationSeconds?
Section titled “durationSeconds?”number
How long the shake takes to decay to nothing; defaults to 1.
frequency?
Section titled “frequency?”number
Oscillation rate; defaults to 10, which is what the engine’s own shake runs at.
Returns
Section titled “Returns”boolean
True when a camera was there to shake.
Example
Section titled “Example”Camera.shake(3, 0.6);stopShake()
Section titled “stopShake()”stopShake():
boolean
Cancels a running shake.
Returns
Section titled “Returns”boolean
True when a camera was there to cancel it on.
worldToScreen()
Section titled “worldToScreen()”worldToScreen(
x,y,z):ScreenPosition
Projects a world-space position to display pixel coordinates.
Parameters
Section titled “Parameters”number
World X coordinate.
number
World Y coordinate.
number
World Z coordinate.
Returns
Section titled “Returns”Screen coordinates and whether the point is visible through the active camera.
Example
Section titled “Example”const point = Camera.worldToScreen(10, 20, 5);if (point.visible) { // point.x and point.y are display pixels.}