I’m trying to make a smooth camera that follows the player around, currently it works but one of the main problems is that it jitters or stutters behind the player or sometimes even goes infront of the player at times causing it not to be smooth at all.
CurrentCamera.CFrame = CFrame.new(
Lerp(LastX, workspace.campart.Position.X, 0.2),
Lerp(LastY, workspace.campart.Position.Y, 0.1),
Lerp(LastZ, workspace.campart.Position.Z, 0.2)
) -- Everything below this point is for Camera rotation and distance.
* Vector3ToRadians(cameraRotation, 0, 1, 0)
* CFrame.new(0, 1.5, 0)
* Vector3ToRadians(cameraRotation, 1, 0, 0)
* CFrame.new(0, 0, cameraDistance)
DebugInfo:UpdateInfo("Camera CFrame", CurrentCamera.CFrame) -- Updates my Debug HUD.
-- Stores the Last Values to be used in the lerp.
LastY = workspace.campart.Position.Y
LastX = workspace.campart.Position.X
LastZ = workspace.campart.Position.Z
This is the code for the camera.
local function Lerp(a, b, alpha)
return a + ((b - a) * alpha)
end
local function Vector3ToRadians(v1)
return CFrame.Angles(math.rad(v1.X), math.rad(v1.Y), math.rad(v1.Z))
end
These are my 2 functions used in the code for the camera.
This is all ran in a RenderStepped under the function UpdateCamera, Server Ownership does not change anything, it being on a BasePart or the Roblox Character itself doesn’t change anything as well. The custom Lerp function also doesnt change anything as just using a Vector3 or CFrame Lerp does the exact same thing and im completely stumped.
Examples of the stutter:
Demo File, script is in StarterPlayerScripts, Ignore “campart”
DemoFile.rbxl (54.3 KB)