UevKF8zjRV_WEtpJsXhr
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

Inherited from Instance: Show Hide

int

DataCost

[ReadOnly] [NotReplicated]

The cost of saving the instance using data persistence.

Instance

Parent

Determines the hierarchical parent of the Instance.

bool

RobloxLocked

If true, the Instance and its descendants cannot be indexed or edited by a Script or LocalScript and will throw an error if it is attempted.

string

ClassName

[ReadOnly] [NotReplicated]

A read-only string representing the class this Instance belongs to.

string

Name

A non-unique identifier of the Instance.

bool

Archivable

Determines if an Instance can be cloned using /Instance/Clone or saved to file.

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

Inherited from Instance: Show Hide

Instance

FindFirstChild ( string name , bool recursive )

Returns the first child of the Instance found with the given name.

Array

GetDescendants ( )

[CustomLuaState]

Returns an array containing all of the descendants of the instance

Objects

GetChildren ( )

Returns an array containing all of the Instance's children.

void

Destroy ( )

Sets the Instance/Parent property to nil, locks the Instance/Parent property, disconnects all connections and calls Destroy on all children.

RBXScriptSignal

GetPropertyChangedSignal ( string property )

Get an event that fires when a given property of an object changes.

string

GetFullName ( )

Returns a string describing the Instance's ancestry.

Instance

FindFirstChildWhichIsA ( string className , bool recursive )

Returns the first child of the Instance for whom Instance/IsA returns true for the given className.

bool

IsAncestorOf ( Instance descendant )

Returns true if an Instance is an ancestor of the given descendant.

bool

IsDescendantOf ( Instance ancestor )

Returns true if an Instance is a descendant of the given ancestor.

Instance

FindFirstChildOfClass ( string className )

Returns the first child of the Instance whose Instance/ClassName|ClassName is equal to the given className.

Instance

FindFirstAncestorWhichIsA ( string className )

Returns the first ancestor of the Instance for whom Instance/IsA returns true for the given className.

Instance

FindFirstAncestorOfClass ( string className )

Returns the first ancestor of the Instance whose Instance/ClassName is equal to the given className.

Instance

FindFirstAncestor ( string name )

Returns the first ancestor of the Instance whose Instance/Name is equal to the given name.

bool

IsA ( string className )

Returns true if an Instance's class matches or inherits from a given class

Instance

WaitForChild ( string childName , double timeOut )

[CustomLuaState] [CanYield]

Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does.

string

GetDebugId ( int scopeLength )

[NotBrowsable]

Returns a coded string of the Instances DebugId used internally by Roblox.

Instance

Clone ( )

Create a deep copy of a Roblox instance and descendants where Archivable = true.

void

ClearAllChildren ( )

This function destroys all of an Instance's children.

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

Inherited from Instance: Show Hide

RBXScriptSignal

DescendantRemoving ( Instance descendant )

Fires immediately before a descendant of the Instance is removed.

RBXScriptSignal

AncestryChanged ( Instance child , Instance parent )

Fires when the Instance/Parent property of the object or one of its ancestors is changed.

RBXScriptSignal

ChildAdded ( Instance child )

Fires when an object is parented to this Instance.

RBXScriptSignal

ChildRemoved ( Instance child )

Fires when a child is removed from this Instance.

RBXScriptSignal

DescendantAdded ( Instance descendant )

Fires when a descendant is added to the Instance.

RBXScriptSignal

Changed ( string property )

Fired immediately after a property of an object changes.