How do I make the camera stay stationary in CFrame (while still being able to move indirectly) when the player is not moving

The player should be able to freely rotate the camera, but it should stay in the received CFrame when the player stops moving. To provide a better example, this is similar to how the camera behaves in SCP: Containment Breach. In general, it is necessary to solve the problem of smoothly stopping the camera when the player stops, so that these camera movements look great! At the moment, the camera slows down sharply when the player is braking, it is ugly and strange.

I provide you with the code:

function Lerp(a, b, t) 
	return (a + (b - a) * t) 
end 

function GetCurve(frequency, intensity) 
	return math.sin(os.clock() * frequency) * intensity 
end 

local previousvelocity = 0

local isVelocity = false

RNS.RenderStepped:Connect(function()
	local velocity = math.round(Vector3.new(HRP.AssemblyLinearVelocity.X, 0, HRP.AssemblyLinearVelocity.Z).Magnitude)

	if velocity > 1 then
		if previousvelocity < velocity then
			previousvelocity = velocity
		end
		isVelocity = false
		camera.CFrame *= CFrame.new(0, GetCurve(verFrequency, verIntensity) * previousvelocity / defWalkSpeed, 0) * CFrame.Angles(0, 0, math.rad(GetCurve(rotFrequency, rotIntensity) * previousvelocity / defWalkSpeed))
	end
	if velocity <= 0 and not isVelocity then
		isVelocity = true
		camera.CFrame *= CFrame.new(0, GetCurve(verFrequency, verIntensity) * previousvelocity / defWalkSpeed, 0) * CFrame.Angles(0, 0, math.rad(GetCurve(rotFrequency, rotIntensity) * previousvelocity / defWalkSpeed))
	end
end)

Reference: https://www.youtube.com/watch?v=OKKkS7HyWbI
That’s a video demonstrating this problem:

P. S. This is a re-created post, since the previous one has stopped being discussed.