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

CameraType

Camera

CameraType

The default Roblox camera scripts have several built in behaviors. Setting the CameraType of a player’s Camera will toggle between these behaviors. Note some CameraType’s require a valid Camera/CameraSubject to work correctly.

  • Fixed: Camera is stationary
  • Follow: Camera moves with the Camera/CameraSubject and rotates to keep the subject in the center of view
  • Attach: Camera moves with the Camera/CameraSubject at a fixed offset and will rotate as the subject rotates
  • Track: Camera moves with the Camera/CameraSubject but does not rotate automatically
  • Watch: Camera is stationary but will rotate to keep the Camera/CameraSubject in the center of view
  • Custom: Default
  • Scriptable: No default behavior. Used by developers to script custom behavior

The above only applies when you use the default Roblox camera scripts. If you write your own camera scripts, you can choose to listen to CameraType and implement your own behaviors or ignore the property entirely.

Manually controlling the Camera

In some cases you may wish to manually control the Camera (for example during a cut-scene). The best way to do this is by setting the CameraType to ‘Scriptable’. The default camera scripts will not move or update the Camera on its own if CameraType is set to ’Scriptable’. This means you can freely modify the Camera using its properties and functions. For more information on positioning and orientating the Camera manually see the Camera/CFrame|Camera.CFrame page.

If you want complete control over the camera at all times, you may replace the default camera scripts with your own.


Code Samples


Basic Camera Cutscene

In this code sample a simple Camera animation is played after the Players/LocalPlayer spawns using TweenService. The Camera/CameraType of the Camera is set to ‘Scriptable’ so the default camera scripts do not interfere.

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer
local camera = workspace.CurrentCamera

function playCutscene(character)
	local primaryPart = character.PrimaryPart

	camera.CameraType = Enum.CameraType.Scriptable 
	

	local baseCFrame = primaryPart.CFrame * CFrame.new(0, 0, -100) * CFrame.Angles(0, math.pi, 0)
	local targetCFrame = primaryPart.CFrame * CFrame.new(0, 0, -10) * CFrame.Angles(0, math.pi, 0)

	camera.CFrame = baseCFrame 

	local tween = TweenService:Create(
		camera,
		TweenInfo.new(2),
		{CFrame = targetCFrame}
	)

	tween:Play()
	tween.Completed:Wait()
	camera.CameraType = Enum.CameraType.Custom
end

localPlayer.CharacterAdded:Connect(function(character)
	wait(3)
	playCutscene(game.Players.LocalPlayer.Character)
end)