3rd person smooth camera starts shaking

I want to make the Camera follow the character Smoothly

The problem is, when player is going in high speeds, the character or the camera starts glitching. (Jittery movement)

I haven’t found any help on dev forum.

This is my Local Script:

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera:Camera = workspace.CurrentCamera

local targetPos = nil
local smoothness = 0.06 
local followDistance = 10 
local verticalOffset = Vector3.new(0, 2, 0)

RunService:BindToRenderStep("SmoothFlightCam", Enum.RenderPriority.Camera.Value, function()
	local char = player.Character
	if not char then return end
	if char:GetAttribute("fly") == false then
		return
	end


	camera.CameraType = Enum.CameraType.Custom

	local hrp = char:FindFirstChild("HumanoidRootPart")
	if not hrp then return end

	local desiredCenterPos = hrp.Position + verticalOffset

	if not targetPos then
		targetPos = desiredCenterPos
	end

	targetPos = targetPos:Lerp(desiredCenterPos, smoothness)

	local lookDir = camera.CFrame.LookVector
	local camPos = targetPos - lookDir * followDistance

	--camera.CFrame = CFrame.new(camPos)
	camera.CFrame = CFrame.lookAt(camPos, targetPos)
end)

Try using CameraType.Scriptable instead of CameraType.Custom.

Since you’re updating the camera’s CFrame each frame, the LookVector`keeps shifting slightly, which makes a jitter when you move a lot or rotate. You can fix using the HumanoidRootParts LookVector and shifting the camera back based on that.

When I change the CameraType to Scriptable, I can’t no longer move the camera with mouse.
Can you tell me more about your solution using HumanoidRootParts LookVector?

I think I made a mistake. I think the jittery movement is because when the character is moving It tries to slow the camera movement down with lerp, and then next frame the lerp might be slower or faster because the closer you get to the camera it starts to slow down.

Instead you could implement something like this:

local MoveDir = (targetPos - desiredCenterPos).Unit
local MoveSpeed = 0.05
if (targetPos - desiredCenterPos).Magnitude =< MoveSpeed then
    targetPos = desiredCenterPos
else
    targetPos = targetPos + MoveDir * MoveSpeed
end

What this does is it just moves it by a set distance every time so it doesn’t jitter every time is speeds up or slows down.

You could also change MoveSpeed relative to the speed of the player flying. Otherwise im not very sure on how to fix this problem