Camera

Camera : Instance

Overview

Properties

CFrame

CFrame

CFrame property in the Camera class defines the position and orientation of a camera in 3D space.

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 sets the angle of the Camera's vertical field of view as a property in Camera.

Code Samples

local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera

Camera.FieldOfView = 150

ViewportSize

Vector2

ViewportSize is a property representing the dimensions, in pixels, of the viewport.

Code Samples

local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera

print(Camera.ViewportSize)

CameraOffset

Vector3

CameraOffset is the offset value representing the distance from the camera's position to the camera subject.

Code Samples

local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera

Camera.CameraOffset = Vector3.new(90, 90, -120)

CameraSubject

Instance

The CameraSubject property determines the object the camera follows. Typically, this is assigned to a character or another in-game object.

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

The CameraType property, of type Enum.CameraType, specifies the camera mode for game development. This allows developers to choose various camera modes or functions, like first-person, third-person, fixed, or subject-following cameras, for different use cases in their gameplay experiences.

Code Samples

local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable

Methods

ViewportPointToRay

Creates a ray from the camera position to the Viewpoint position.

Parameters

number x

number y

number depth

Currently not supported.

Return

Ray

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

Creates a ray from the camera position to the ScreenPoint position.

Parameters

number x

number y

number depth

Currently not supported.

Return

Ray

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

This function returns the screen location and depth of a vector3 worldPoint and whether this point is visible on the screen or not.

Parameters

Vector3 WorldPoint

Return

Tuple

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

The GetLargestCutoffDistance method, which can take either a list of instances to ignore, returns the largest cutoff distance as a Lua value, indicating how much the Camera needs to be pushed towards its Focus to ensure there are no obstructions between the Camera.Focus and Camera.CFrame.

Parameters

array InIgnoreList

Return

Value

number

Code Samples

local Workspace = game:GetService("Workspace")

local Camera = Workspace.CurrentCamera
local IgonoreList = {}
local Distance = Camera:GetLargestCutoffDistance(IgonoreList)

print(Distance)	

Events

See also

Camera

Last updated