I’m trying to make an over-the-shoulder camera system and I’m using CFrame:Lerp to make the camera lag slightly behind the mouse movement to make it feel smoother, but it ends up looking jittery and sometimes the player doesn’t end up facing where it should. Any ideas how to fix?
Here’s my code:
local function playerInput(actionName, inputState, inputObject)
-- Calculate camera/player rotation on input change
if inputState == Enum.UserInputState.Change then
cameraAngleX = cameraAngleX - inputObject.Delta.X
-- Reduce vertical mouse/touch sensitivity and clamp vertical axis
cameraAngleY = math.clamp(cameraAngleY-inputObject.Delta.Y*0.4, -75, 75)
-- Rotate root part CFrame by X delta
local rootPartCFrame = rootPart.CFrame
local newRootPartCFrame = CFrame.new(rootPart.Position) * CFrame.Angles(0, math.rad(cameraAngleX), 0)
rootPart.CFrame = rootPartCFrame:Lerp(newRootPartCFrame, 0.35)
end
end
A video of the issue: Video