Camera

Camera : Instance

Overview

The camera defines the viewpoint of viewing the 3D space and how the camera behaves.

Description

Camera plays a crucial role by managing the camera's position, orientation, field of view, and viewport size. It interacts with other game objects to provide seamless camera experiences for players. Its Lua scripting allows developers to create scenes, control player perspectives, and manipulate cameras according.

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 CurrentCam = Workspace.CurrentCamera

print(CurrentCam.CFrame)

Focus

CFrame

Focus represents the position and direction the camera is looking at.

Code Samples

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

print(CurrentCam.Focus)

FieldOfView

number

FieldOfView sets the angle of the Camera's vertical field of view as a property in Camera.

Code Samples

local Camera = workspace.CurrentCamera

Camera.FieldOfView = 150

ViewportSize

Vector2

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

Code Samples

local Camera = workspace.CurrentCamera

print(Camera.ViewportSize)

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 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

Return

Ray

Code Samples

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

Return

Ray

Code Samples

local Camera = workspace.CurrentCamera
	
local ViewportSize = Camera.ViewportSize
local ViewportPointToRay = Camera:ScreenPointToRay(ViewportSize.X / 2, ViewportSize.Y / 2)
print("Ray Origin : ", ViewportPointToRay.Origin)
print("Ray Direction : ", ViewportPointToRay.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

//NotWork//

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

Code Samples

Events