PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

Camera

Show deprecated

Camera

Show deprecated

The Camera object defines a view of the 3D game world.

Where the Camera object is found

In an instance of the game, each client has its own Camera object associated with it. Camera objects exist only upon the viewer’s client, residing in that user’s local Workspace, and therefore cannot be edited directly from the server.

Each client’s particular Camera object can be accessed through the Workspace/CurrentCamera property of the Workspace on that client.

Note, Workspace/CurrentCamera can also be used to find the Camera object in Roblox Studio.

How the Camera object works

The Camera’s properties define the current view of the 3D game world. The most important of these being:

  • The Camera/CFrame property represents the position and orientation of the camera.
  • The Camera/Focus property represents the point the camera is looking at. It is important this property is set as it also represents where the game thinks you are in the world. Certain visuals will be more detailed and will update more frequently, depending on how close they are to the Focus. Roblox’s default camera scripts take care of this.
  • The Camera/CameraType property is read by the game’s camera scripts and determines how the Camera should update each frame.
  • The Camera/CameraSubject property is read by the game’s camera scripts and determines what object the Camera should follow.
  • The Camera/FieldOfView property represents the extent of the observable world visible.
  • An internal roll amount, set by Camera/SetRoll, determines the angle the camera is rotated by on the longitudinal axis (the roll).

How to work with the Camera

Roblox’s camera scripts update the Camera’s properties every frame dependent on the current Camera/CameraType. This means developers looking to control the Camera themselves have two options.

  1. Setting the Camera/CameraType property to ‘Scriptable’. When the Camera is in ‘Scriptable’ mode the default camera scripts will not update the camera. In most cases this is the easiest option.
  2. Replacing or modifying the default camera scripts in StarterPlayerScripts|StarterPlayer.StarterPlayerScripts. This is only recommended for advanced developers.

Properties

CFrame

CFrame

The DataType/CFrame of the Camera, defining its position and orientation in the 3D world

Instance

CameraSubject

The Humanoid or BasePart that is the Camera|Camera's subject

CameraType

CameraType

Specifies the Enum/CameraType to be read by the camera scripts

float

FieldOfView

Sets the angle of the Camera|Camera's vertical field of view

CFrame

Focus

Sets the area in 3D space that is prioritized by Roblox’s graphical systems

bool

HeadLocked

Toggles whether the Camera will automatically track the head motion of a player using a VR device

float

HeadScale

Sets the scale of the user’s head when using VR

float

NearPlaneZ

[ReadOnly] [NotReplicated]

Describes the negative z-offset, in studs, of the Camera|Camera's near clipping plane

Vector2

ViewportSize

[ReadOnly] [NotReplicated]

Describes the dimensions, in pixels, of the client’s viewport

Functions

float

GetLargestCutoffDistance ( Objects ignoreList )

Returns how much the Camera needs to be pushed towards its Camera/Focus|Focus in order to make sure there is no obstructions between the Camera/Focus and Camera/CFrame

float

GetPanSpeed ( )

Returns the current ‘pan’ speed of the Camera

Objects

GetPartsObscuringTarget ( Array castPoints , Objects ignoreList )

Returns an array of BasePart|BaseParts that are obscuring the lines of sight between the Camera|Camera’s Camera/CFrame and the castPoints

CFrame

GetRenderCFrame ( )

Returns the actual DataType/CFramewhere the Camera is being rendered, accounting for any roll applied and the impact of VR devices

float

GetRoll ( )

Returns in radians the current roll, or rotation around the Camera|Camera’s Z-axis, applied to the Camera using Camera/SetRoll

float

GetTiltSpeed ( )

Returns the current ‘tilt’ speed of the Camera

void

Interpolate ( CFrame endPos , CFrame endFocus , float duration )

Tweens the Camera in a linear fashion towards a new Camera/CFrame and Camera/Focus over a given duration

void

PanUnits ( int units )

Pans the Camera around the Camera/Focus in 45 degree increments around the Y axis

Ray

ScreenPointToRay ( float x , float y , float depth )

Creates a unit DataType/Ray from a position on the screen (in pixels), at a set depth from the Camera orientated in the Camera|Camera’s direction. Accounts for the GUI inset

void

SetCameraPanMode ( CameraPanMode mode )

Sets the Enum/CameraPanMode to be used by the Camera on mobile devices

void

SetRoll ( float rollAngle )

Sets the current rotation applied around the Camera|Camera’s Z-axis

bool

TiltUnits ( int units )

Tilts the Camera around its Camera/Focus in 10 degree increments around the Camera|Camera’s X axis

Ray

ViewportPointToRay ( float x , float y , float depth )

Creates a unit DataType/Ray from a position on the viewport (in pixels), at a given depth from the Camera orientated in the Camera|Camera’s direction. Does not account for the GUI inset

Tuple

WorldToScreenPoint ( Vector3 worldPoint )

Returns the 2D screen location of a DataType/Vector3 position in the world, the depth of it from the screen and whether it is visible. Accounts for the GUI inset

Tuple

WorldToViewportPoint ( Vector3 worldPoint )

Returns the 2D screen location of a DataType/Vector3 position in the world, it’s from the screen and whether it is visible or not. Does not account for the GUI inset

Events

RBXScriptSignal

FirstPersonTransition ( bool entering )

Fires when the local user’s Camera switches in and out of first person mode

RBXScriptSignal

InterpolationFinished ( )

Fired when the Camera has finished interpolating usingCamera/Interpolate