Camera
Camera : Instance
Overview
The Camera object is an instance that defines the viewpoint from which a player sees the 3D space.
Each client in the runtime environment has its own Camera, accessible through the Workspace.CurrentCamera property.
By modifying the Camera's properties, its position, orientation, or behavior can be adjusted.
Properties
CFrame
CFrame
Specifies the Camera's position and rotation, defining its coordinates and orientation in 3D space.
You can modify this property for direct movement of the Camera, but since the default Camera behavior is tied to the character, to be able to manually control the CFrame, disable automatic updates by setting the CameraType property to Scriptable.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(0, 150, 1000)
Focus
CFrame
Currently not supported.
Code Samples
FieldOfView
number
FieldOfView (FOV) is a property that defines the Camera's viewing angle. The default is 90 degrees and the possible range is between 1 and 169 degrees.
For example, increasing the FOV value when the character sprints can create an effect where the field of view expands, giving the impression of losing control.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
Camera.FieldOfView = 150
ViewportSize
Vector2
This property returns the current screen size. (Read-only)
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
print(Camera.ViewportSize)
CameraOffset
Vector3
This property specifies the relative position of the camera.
This is often used in TPS games to position characters slightly off-center on the screen. This allows you to avoid visual overlap between the crosshair and the character.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
Camera.CameraOffset = Vector3.new(90, 90, -120)
CameraSubject
Instance
This property specifies the subject the camera focuses on.
By default, the camera targets the local character's humanoid object and tracks that object if the CameraSubject is set to BasePart. To revert to the original behavior, simply set the CameraSubject back to the humanoid.
Code Samples
local Workspace = game:GetService("Workspace")
local Part = Workspace:WaitForChild("Part")
local Camera = Workspace.CurrentCamera
Camera.CameraSubject = game.Players.LocalPlayer.Character
CameraType
Enum.CameraType
Defines how the camera behaves, and the default is Custom.
Changing this property switches the Camera mode based on the Enum.CameraType value, and some modes require a CameraSubject to work normally.
When CameraType is set to Scriptable, the default camera control is disabled, and the developer must control the camera's position and orientation by directly modifying the CFrame via script.
Currently, there are two supported modes: Custom and Scriptable.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
EnabledSmoothFollow
bool
This property specifies whether to apply a delay effect when the camera moves.
The default value of true causes the camera to follow the character's movement with a slight delay for a smooth motion. If set to false, the camera immediately responds to the character's movements and follow them.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
print(Camera.EnableSmoothFollow)
SmoothFollowSpeed
number
This property specifies the speed at which the camera interpolates its position when following the character. The default is 5, and the possible range is between 0.1 and 1,000.
This applies only when EnableSmoothFollow is true. A larger value makes it follow immediately, while a smaller value makes it follow more smoothly.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
Camera.SmoothFollowSpeed = 10
FollowMaxDistance
number
This property specifies the maximum distance that the camera can lag behind due to the delay effect when following the character.
This applies only when EnableSmoothFollow is true. The default is 25.
The possible range is between 0.1 and 1,000.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
Camera.FollowMaxDistance = 50.0
EnableSmoothRotation
bool
This property specifies whether to apply a delay effect when the camera rotates. The default is false, meaning the camera responds immediately to the character's rotation.
Setting this value to true causes the camera to slowly follow the character's rotation, creating a smooth rotation effect.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
print(Camera.EnableSmoothRotation)
SmoothRotationSpeed
number
This property specifies the interpolation speed at which the camera follows the character's rotation. The default is 0.1, and the possible range is between 0.1 and 1,000.
This applies only when EnableSmoothRotation is true. A larger value makes the camera respond instantly, while a smaller value creates a smoother rotation effect.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
Camera.SmoothRotationSpeed = 500
Methods
ViewportPointToRay
Receives normalized screen coordinates (0–1) and returns a unit ray in the direction the camera is facing.
Parameters
number
x
The horizontal coordinate ratio on the screen at which the ray will be generated.
number
y
The vertical coordinate ratio on the screen at which the ray will be generated.
number
depth
Currently not supported.
Return
Ray
Returns a ray projected in the direction the camera is facing, starting from the point where screen coordinates are converted into a 3D point.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
local ViewportPointToRay = Camera:ViewportPointToRay(0.5, 0.5)
print("Ray Origin : ", ViewportPointToRay.Origin)
print("Ray Direction : ", ViewportPointToRay.Direction)
ScreenPointToRay
Receives screen coordinates (in pixels) and returns a unit Ray projected in the direction the Camera is facing.
Parameters
number
x
The horizontal coordinate on the screen (in pixels) at which the ray will be generated.
number
y
The vertical coordinate on the screen (in pixels) where the ray will be generated.
number
depth
Currently not supported.
Return
Ray
Returns a ray projected in the direction the camera is facing, starting from the point where screen coordinates are converted into a 3D point.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
local ViewportSize = Camera.ViewportSize
local ScreenPointToRay = Camera:ScreenPointToRay(ViewportSize.X / 2, ViewportSize.Y / 2)
print("Ray Origin : ", ScreenPointToRay.Origin)
print("Ray Direction : ", ScreenPointToRay.Direction)
WorldToViewportPoint
Receives a 3D coordinate as input and returns the position of that point on the screen, along with whether the coordinate is within the screen.
Parameters
Vector3
WorldPoint
The world coordinates.
Return
Tuple
Returns a Vector3 containing the screen X and Y coordinates, along with a boolean indicating whether the given WorldPoint is within the screen.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
local WorldPoint = Vector3.new(0, 50, -200)
local Vector, OnScreen = Camera:WorldToViewportPoint(WorldPoint)
print(Vector, OnScreen)
GetLargestCutoffDistance
(Deprecated) Checks for any objects obstructing the camera's view between the its CFrame position and the Focus point, then calculates and returns how far the camera should move toward the Focus to avoid them.
Parameters
array
InIgnoreList
Instances to ignore during the view processing.
Return
number
This is the calculated distance from the current position to how close the camera must move in the Focus direction to avoid being obscured by obstacles.
Code Samples
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
local IgonoreList = {}
local Distance = Camera:GetLargestCutoffDistance(IgonoreList)
print(Distance)
Events
See also
CameraLast updated