Help with smoothing camera following the head rotation

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Smooth out the camera following head rotation movement, as right now, on some animations with zero fade, it just snaps.

  2. What is the issue? Include screenshots / videos if possible!
    I’m making a parkour game, similar to Mirror’s Edge, and i’ve figured out a method to get the camera to follow the player’s head. However, since theres no smoothing, i’ve tried to lerp the camera movement, however it only adds dampening to it (makes it less strong).

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Lerping the camera, didnt work.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

So I have this block of code that handles the camera following the head rotation

local setoldheadcf = true
		
local thing = head.Orientation.X-oldheadcf.X
local zvar = math.rad(head.Orientation.Z)

local goob

thing = math.clamp(thing,-100,100)
goob = cam.CFrame * CFrame.Angles(math.rad(thing/1.5), 0, zvar)
		
cam.CFrame = goob

if setoldheadcf then
	oldheadcf = head.Orientation
end

when i try lerping the camera’s cframe, as i mentioned before, it adds dampening to it instead of smoothing

cam.CFrame = cam.CFrame:Lerp(goob,0.5) --the same as cam.CFrame = goob/2

ignore my awful variable names, my head is constantly empty so i just write whatever comes to mind

Can you maybe send a video or a screenshot i dont really understand your problem?

Hi @1novaspec,

I tried your script using RunService, but the camera shaking was too much and made my eyes hurt. So, I reduced the shaking and added a variable called “smoothingSpeed” to control how much shaking occurs.

I’m not sure what you meant in your post, but maybe my modification is what you were asking for.

You can reduce or increase “smoothingSpeed”

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

local Player = Players.LocalPlayer

local Char = Player.Character or Player.CharacterAdded:Wait()
local cam = workspace.CurrentCamera

local head = Char:WaitForChild("Head")

local smoothingSpeed = 20 -- Adjust for more or less smoothing
local oldheadcf = head.Orientation 

RunService.RenderStepped:Connect(function(dt)
	local thing = head.Orientation.X - oldheadcf.X
	local zvar = math.rad(head.Orientation.Z)

	thing = math.clamp(thing, -100, 100)

	local targetCFrame = cam.CFrame * CFrame.Angles(math.rad(thing / 1.5), 0, zvar)

	cam.CFrame = cam.CFrame:Lerp(targetCFrame, 1 - math.exp(-smoothingSpeed * dt))

	-- Update old head rotation
	oldheadcf = head.Orientation
end)

im sorry i wasn’t clear

to say it in REALLY simple terms

what i want:
camera go smoothly from its current orientation to the new orientation
i try with lerp
instead of it smoothing out, it does the same thing as dividing it would do and doesn’t smooth it out

e.g. imagine if the head was at a 5 degree orientation on the Z axis
with this example goob would be

cam.CFrame * CFrame.Angles(0,0,5)

since it’s setting the camera’s CFrame, it snaps whenever the head snaps to a orientation
trying to smooth that out with lerp, if i do

cam.CFrame = cam.CFrame:Lerp(goob,0.5)

it’d be the same as “goob” being

cam.CFrame * CFrame.Angles(0,0,2.5)

because 5 * 0.5 is the same as 5/2 which is 2.5

why i think it happens:
roblox resets the camera’s Z orientation every frame, so instead of it lerping from the previous orientation, it lerps from Z being 0, which acts the same as dividing it because… math

(in this example i didnt account for the X rotation which is completely unaffected)

I did it!

instead of goob being cam.CFrame * (camrotationstuff) it’s just the camrotationstuff, then instead of setting it directly to goob, i instead set it to cam.CFrame * goob

this allowed me to use lerp to actually smooth it out by lerping directly in the “goob” variable

local goob --put outside of the heartbeat loop

if goob then
	goob = goob:Lerp(CFrame.Angles(math.rad(thing/1.5), 0, zvar),0.2)
else
	goob = CFrame.Angles(math.rad(thing/1.5), 0, zvar)
end
		
cam.CFrame *= goob```