setCameraMatrix | Multi Theft Auto: Wiki Skip to content

setCameraMatrix

Client-side
Server-side
Shared

Pair: getCameraMatrix

This function sets the camera's position and direction. The first three arguments are the point at which the camera lies, the last three are the point the camera faces (or the point it "looks at").

Note

Calling this function takes the camera's focus away from the player and sets the camera in a fixed position and rotation. The camera's focus can be brought back to the player using the setCameraTarget function.

Tip

Instead of six coordinates, or two vectors, a Matrix can be supplied as position.

OOP Syntax Help! I don't understand this!

Server OOP syntax
  • Method:player:setCameraMatrix(...)
  • Variable: .matrix
Client OOP syntax
  • Method:Camera.setMatrix(...)
  • Variable: .matrix

Client Syntax

bool setCameraMatrix ( float positionX, float positionY, float positionZ, [ float lookAtX = 0, float lookAtY = 0, float lookAtZ = 0, float roll = 0, float fov = 70 ] )
Required Arguments
  • positionX: The x coordinate of the camera's position.
  • positionY: The y coordinate of the camera's position.
  • positionZ: The z coordinate of the camera's position.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • lookAtX (default: 0): The x coordinate of the point the camera faces.
  • lookAtY (default: 0): The y coordinate of the point the camera faces.
  • lookAtZ (default: 0): The z coordinate of the point the camera faces.
  • roll (default: 0): The camera roll angle, -180 to 180. A value of 0 means the camera sits straight, positive values will turn it counter-clockwise and negative values will turn it clockwise. -180 or 180 means the camera is upside down.
  • fov (default: 70): The field of view angle, 0.01 to 179. The higher this value is, the more you will be able to see what is to your sides.

Returns

  • bool: result

Returns true if the arguments are valid, false otherwise.

Server Syntax

bool setCameraMatrix ( player thePlayer, float positionX, float positionY, float positionZ, [ float lookAtX = 0, float lookAtY = 0, float lookAtZ = 0, float roll = 0, float fov = 70 ] )
Required Arguments
  • thePlayer: The player whose camera is to be changed.
  • positionX: The x coordinate of the camera's position.
  • positionY: The y coordinate of the camera's position.
  • positionZ: The z coordinate of the camera's position.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • lookAtX (default: 0): The x coordinate of the point the camera faces.
  • lookAtY (default: 0): The y coordinate of the point the camera faces.
  • lookAtZ (default: 0): The z coordinate of the point the camera faces.
  • roll (default: 0): The camera roll angle, -180 to 180. A value of 0 means the camera sits straight, positive values will turn it counter-clockwise and negative values will turn it clockwise. -180 or 180 means the camera is upside down.
  • fov (default: 70): The field of view angle, 0.01 to 179. The higher this value is, the more you will be able to see what is to your sides.

Returns

  • bool: result

Returns true if the arguments are valid, false otherwise.

Code Examples

client

This code fixates the camera onto the Vinewood sign in Los Santos for local player that joins the server.

function setCameraOnResourceStart()
-- slowly fade the camera in to make the screen visible
fadeCamera(true, 5)
-- set the player's camera to a fixed position, looking at a fixed point
setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316)
end
addEventHandler("onClientResourceStart", resourceRoot, setCameraOnResourceStart)