Camera
constCamera:object
Defined in: client/api.d.ts:2197
The view this client is drawing through. Nothing here is replicated and nothing here is authority: it describes one machine’s own camera at one moment.
This is the game’s camera, not a camera of the mod’s own – it follows the player, a dialogue, a cutscene or a free flight, whichever the game currently has. NoClip is what takes it over, setThirdPerson puts it behind the player, and setShot stands it somewhere in the world.
Type Declaration
Section titled “Type Declaration”clearShot()
Section titled “clearShot()”clearShot(
duration?):void
Gives the player their own view back. Does nothing without a shot.
Parameters
Section titled “Parameters”duration?
Section titled “duration?”number
How long the glide back into the player’s eyes takes, in milliseconds: 0, the default, is a cut, and the most is 60000. The glide follows the player if they move meanwhile. With setThirdPerson on, it ends behind them instead and their head stays drawn.
Returns
Section titled “Returns”void
getPose()
Section titled “getPose()”getPose():
CameraPose|null
Where the camera is this frame, and what it can see from there.
Returns
Section titled “Returns”CameraPose | null
The pose, or null in the main menu and across a level load, when there is no active view at all.
isShotActive()
Section titled “isShotActive()”isShotActive():
boolean
Whether a shot holds the view.
Returns
Section titled “Returns”boolean
True from setShot, including its glide in, until clearShot; false already while gliding back.
isThirdPerson()
Section titled “isThirdPerson()”isThirdPerson():
boolean
Whether setThirdPerson is on.
Returns
Section titled “Returns”boolean
True from setThirdPerson until it is turned off, also while it waits for a body or for NoClip.
screenRay()
Section titled “screenRay()”screenRay(
options?):CameraRay|null
A ray out of the camera through a point on screen. This is what turns “what is the player looking at” into the two points World.raycast takes.
Parameters
Section titled “Parameters”options?
Section titled “options?”x and y are a point on screen in normalized device coordinates – both run -1 at the left and bottom to +1 at the right and top, so the default (0, 0) is the centre of the screen, which is where the crosshair is. range is how far out to carry target, in metres, 100 by default and up to 4096.
range?
Section titled “range?”number
number
number
Returns
Section titled “Returns”CameraRay | null
The ray, or null when there is no active view.
setShot()
Section titled “setShot()”setShot(
options):boolean
Films this player’s view from a fixed point: what a cutscene, an intro or a kill cam is made of.
The camera holds there until clearShot – or until another setShot, which glides on from wherever this one is. Nothing about the player’s controls changes; a gamemode that wants them still says so through Controls. The player’s head, which the game keeps out of its first person, is drawn for as long as the camera is looking at them from outside their eyes.
There is one view to draw through. A shot outranks setThirdPerson, which takes over again when the shot ends, and NoClip cannot start while it holds. The map, the inventory and the other pause-screen pages are filmed by the game’s own camera, so the shot steps aside while one is open and comes back when it closes. A shot ends with the session.
The server can send the same shot with its own Camera.setShot(player, options); whichever comes last wins.
Parameters
Section titled “Parameters”options
Section titled “options”position is where the camera stands and lookAt the point it faces, both in world space. duration is how long it takes to get there from wherever the view is now, in milliseconds: 0, the default, is a cut, and the most is 60000. fov is the vertical field of view in degrees, 20 to 120; leave it out to keep the player’s own.
duration?
Section titled “duration?”number
number
lookAt
Section titled “lookAt”position
Section titled “position”Returns
Section titled “Returns”boolean
True, or false while NoClip is flying or when position and lookAt are the same point.
setThirdPerson()
Section titled “setThirdPerson()”setThirdPerson(
options?):void
Puts this player’s camera behind them, for as long as it is on.
The game has no third-person view to switch to, so this is a camera of the mod’s own, placed every frame behind the body along the direction the player is looking. Nothing about their controls changes: they walk and turn as they did, and the mouse still turns the body. When a wall is behind them the camera comes in along the same line rather than going through it. Their head, which the game keeps out of its own first person, is drawn for as long as this camera is the one looking at them.
This is what a disguised player needs – player.setDisguise hides the body the game’s own camera sits in. It is this client’s own view, so a gamemode turns it on from a client script, typically on an event the server sends the disguised player.
There is one view to draw through: NoClip cannot start while this holds it, and while NoClip flies this waits. The map, the inventory and the other pause-screen pages are filmed by the game’s own camera, so this steps aside while one is open and comes back when it closes. It lasts until the session ends.
Parameters
Section titled “Parameters”options?
Section titled “options?”{ distance?: number; height?: number; shoulder?: number; } | null
Where the camera sits, in metres: distance back from the body along where the player looks (3.5 by default, 0.3 to 20), height of the point it orbits above the body’s feet (1.6, up to 5 either way), and shoulder to the right of it, negative for the left (0, up to 3 either way). Null hands the view back to the game’s own camera. Called again while on, it only moves the camera.
Returns
Section titled “Returns”void