Camera
constCamera:object
Defined in: client/api.d.ts:637
The camera the world renders through, as of the last frame, whichever state holds it: first or third person, the fly camera, a scripted one.
Type Declaration
Section titled “Type Declaration”forceFirstPerson()
Section titled “forceFirstPerson()”forceFirstPerson():
boolean
Puts the player’s camera in first person, as Game.ForceFirstPerson does. The game only does it while the camera follows the player.
Returns
Section titled “Returns”boolean
False before the camera exists.
forceThirdPerson()
Section titled “forceThirdPerson()”forceThirdPerson():
boolean
Puts the player’s camera in third person, as Game.ForceThirdPerson does. The game refuses from some states, such as furniture, and waits for an open menu to close.
Returns
Section titled “Returns”boolean
False before the camera exists.
getCrosshairTarget()
Section titled “getCrosshairTarget()”getCrosshairTarget(): {
distance:number;entity:number|null;ref:number; } |null
What lies under the crosshair, as the game picks it for the activation prompt, the activate button and VATS: the reference, the network ID of the player or NPC it stands for when it is one, and how far it is from the player in game units.
Returns
Section titled “Returns”{ distance: number; entity: number | null; ref: number; } | null
Null with nothing under the crosshair. It is the activation pick: an actor is under it only when the game offers to activate it, so another player’s body never is; Camera.raycast strikes it.
getFov()
Section titled “getFov()”getFov(): {
horizontal:number;vertical:number; } |null
The field of view the world renders with, in degrees, across and up the screen. Null before the world is built.
Returns
Section titled “Returns”{ horizontal: number; vertical: number; } | null
getPosition()
Section titled “getPosition()”getPosition(): {
x:number;y:number;z:number; } |null
Where the camera is, in world units; null before the world is built.
Returns
Section titled “Returns”{ x: number; y: number; z: number; } | null
getRotation()
Section titled “getRotation()”getRotation(): {
pitch:number;yaw:number; } |null
Where the camera looks: pitch in radians, positive down; yaw in radians in [0, 2pi), 0 facing +Y, clockwise. Null before the world is built.
Returns
Section titled “Returns”{ pitch: number; yaw: number; } | null
getScreenSize()
Section titled “getScreenSize()”getScreenSize():
object
The game’s back buffer, in pixels: the space worldToScreen answers in.
Returns
Section titled “Returns”object
height
Section titled “height”height:
number
width:
number
getTarget()
Section titled “getTarget()”getTarget():
number|null
The network ID of the body the camera was told to follow; null while it follows the player’s own.
Returns
Section titled “Returns”number | null
isFirstPerson()
Section titled “isFirstPerson()”isFirstPerson():
boolean
Whether the player’s camera is in its first-person state.
Returns
Section titled “Returns”boolean
False in third person and in every other state: the fly camera, furniture, a scripted camera.
raycast()
Section titled “raycast()”raycast(
distance?,options?): {entity:number|null;fraction:number;hit:boolean;normal:Vector3;position:Vector3;ref:number|null; } |null
What the player is aiming at: World.raycast from the camera through the middle of the screen, where the crosshair sits, in first or third person. Unlike getCrosshairTarget it strikes anything solid, other players’ bodies included.
Parameters
Section titled “Parameters”distance?
Section titled “distance?”number
How far to look, in game units; 10000 when left out.
options?
Section titled “options?”As World.raycast’s: the actor whose body the ray passes over, the local player by default.
ignore?
Section titled “ignore?”number | string | null
Returns
Section titled “Returns”{ entity: number | null; fraction: number; hit: boolean; normal: Vector3; position: Vector3; ref: number | null; } | null
As World.raycast’s; null before the world is built or the player is in a cell.
setFov()
Section titled “setFov()”setFov(
degrees):boolean
Sets the field of view the world renders with, as FiveM’s SetCamFov and the console’s fov do: a zoom for a cutscene, a fish-eye for a drunk effect. It holds through camera changes until set again; the game’s own comes back with null or when the session ends. The player’s own settings are not touched.
Parameters
Section titled “Parameters”degrees
Section titled “degrees”number | null
The horizontal field of view, 10 to 160 degrees; null for the game’s own.
Returns
Section titled “Returns”boolean
False before the world is built.
setTarget()
Section titled “setTarget()”setTarget(
entityId):boolean
Makes the camera follow another body in third person, as Game.SetCameraTarget does: what a spectator mode is built on. The player’s own body stays where it is and still takes its input; the camera comes back by itself when the body followed leaves this game.
Parameters
Section titled “Parameters”entityId
Section titled “entityId”number | null
The network ID of a player or an NPC, as the server knows it (player.id); null for the player’s own body.
Returns
Section titled “Returns”boolean
False when no such player or NPC has a body loaded here.
setView()
Section titled “setView()”setView(
view):boolean
Takes the camera from the player and puts it where the script says, as FiveM’s CreateCam, SetCamCoord, PointCamAtCoord and RenderScriptCams do: a cutscene shot, a security camera, an intro flight. The player’s controls move neither the camera nor their body while it is up: their movement, looking, jumping and fighting are held off, and their body keeps its heading. Called again it moves: a script tweens it by calling every tick. It is given back with null, when the resource that set it stops, or when the session ends.
Parameters
Section titled “Parameters”{ lookAt?: Vector3; position: Vector3; rotation?: { pitch: number; yaw: number; }; } | null
Where the camera stands, and where it looks: a rotation in radians (pitch positive down, yaw 0 facing +Y, clockwise) or a point to face. Null gives the player their camera back.
Returns
Section titled “Returns”boolean
False when there is no player in a cell, or the console’s fly camera holds the camera.
worldToScreen()
Section titled “worldToScreen()”worldToScreen(
x,y,z): {onScreen:boolean;x:number;y:number; } |null
Projects a world point through last frame’s camera into back-buffer pixels, origin top left (see getScreenSize; scale by the web view’s size over it). onScreen is false for a point in front of the camera but outside the view. Null for a point behind the camera, or before the world is built.
Parameters
Section titled “Parameters”number
World units.
number
World units.
number
World units.
Returns
Section titled “Returns”{ onScreen: boolean; x: number; y: number; } | null