In one of my games, after a jumpscare has moved the camera’s Cframe and changed its mode to scriptable, how can I revert the camera to focus on the player again like before?
Reverting the action is simple enough. Camera type has to be restored to the original type, and camera subject should be switched back to the humanoid.
local camera = workspace.CurrentCamera
local prevCameraType = camera.CameraType
-- jumpscare
camera.CameraType = prevCameraType
camera.CameraSubject = humanoid
For more fluid experience a transition can be added. Camera’s CFrame is then stored right before camera type becomes scriptable, later to be used in a tween (or in a Bezier curve) moving the camera back to its previous position.
Settings camera’s subject also automatically sets camera.Focus
to default.
Example
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local head = character:WaitForChild("Head")
task.wait(5)
print("Began")
local prevCameraType = camera.CameraType
local prevCameraCF = camera.CFrame
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.lookAt(Vector3.new(0,25,0), head.Position)
humanoid.WalkSpeed = 0
task.wait(5)
print("Moving back")
local tween = TweenService:Create(
camera,
TweenInfo.new(1.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{CFrame = prevCameraCF}
)
tween:Play(); tween.Completed:Wait()
camera.CameraType = prevCameraType
camera.CameraSubject = humanoid
humanoid.WalkSpeed = 16
This worked, thanks
I tried this at the start in fact and it did work then, but my workspace is at night so I thought it didn’t work I’m an idiot
Anytime, and good luck with your project!
Haha, believe it or not, something similar happened to me a couple of days ago!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.