I’m trying to create a first person smooth camera like that of Doors, (besides seeing your body). I’ve been avoiding setting the camera type to “scriptable” because it would break other systems in my game. I’ve looked at lots of other posts about this topic but haven’t found anything that does what I want to achieve without setting the camera to “scriptable”
So far, I have this:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid"):: Humanoid
local HRP = character:WaitForChild("HumanoidRootPart"):: Part
local camera = workspace.CurrentCamera
local clamp = math.clamp
local targetX, targetY = 0, 0
local MAX_ANGLE = 80
local MIN_ANGLE = 90
local SPEED = 2
local SENSITIVITY = .8
local RELEASE_DECEL = .5
UIS.MouseDeltaSensitivity = 0.01
RunService.RenderStepped:Connect(function()
local x, y, z = camera.CFrame:ToOrientation()
local delta = UIS:GetMouseDelta()
if clamp(y, -MIN_ANGLE, MAX_ANGLE) == y then
targetX += delta.X
end
targetY += delta.Y
targetX *= RELEASE_DECEL
targetY *= RELEASE_DECEL
camera.CFrame *= CFrame.fromOrientation(-targetY * SENSITIVITY, -targetX * SENSITIVITY, 0)
end)
It works, but can be jittery and unstable sometimes, and I don’t know how to fix it. I’m fine with rewriting it as long as it achieves an effect like Doors without being this unstable.