# Help to understand Linear Interpolation and CFrame

Hello, I’m new at Roblox Studio.

So, I’m trying to make a very realistic and smooth camera in roblox studio for my first person roblox game but encounter a problem.

I’m trying to figure out why when i use lerp and the first value become the goal in my RenderStepped loop, the camera rotate back as smoothly as the lerp function to the position where it should be (the position of the mouse).

I tried to print the different values of the CFrame angles and more but couldn’t find why it does this.
Do someone know why this effect occur and how to stop it ?

Here’s the video (don’t mind the z axis rotation effect) :

Here’s the script I use for the OverShoot effect :

``````local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

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

local LastFrameTime
local CurrentFrameTime

local Rotation_X = 0
local Rotation_Y = 0
local Rotation_Z = 0

--local Speed_Scale_X = (math.abs(Delta_Scale_X) / DeltaTimeInSecond)
--local Delta_Scale_X = (MouseDelta.X / Mouse.ViewSizeX) * 100
--if LastFrameTime == nil then LastFrameTime = tick() return end
--CurrentFrameTime= tick()
--local SmoothFactor = 0
--LastFrameTime = tick()

local Camera = workspace.CurrentCamera

local LastCFrame = Camera.CFrame

RunService.RenderStepped:Connect(function(step)
local MouseDelta = UIS:GetMouseDelta()

Rotation_Z = lerp(Rotation_Z,math.clamp(MouseDelta.X, -6, 6), step*6)

local OverShoot_X = MouseDelta.X * 0.1
Rotation_X = lerp(Rotation_X,math.clamp(OverShoot_X, -40, 40) , 0.05)

--for debug
print("Corrected OverShoot_X : ",Rotation_X)
print("Last Radian Angle X Axis : ",ActualRadian_X)