Advice on fixing an unstable camera script

Hello DevForum,

I am making a game where the camera always follows the player from one specific angle. I’ve implemented the following script in StarterPlayerScripts to achieve this:

local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable

game:GetService("RunService").RenderStepped:Connect(function()
	local c = game.Players.LocalPlayer.Character
	if not c then return end
	local h = game.Players.LocalPlayer.Character:FindFirstChild("Head")
	local hrp = game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
	if not h then return end
	
	local pos = hrp.Position + Vector3.new(0,5,-15) -- Aribitrary, can tweak if necessary.
	local lookAt = h.Position
	cam.CFrame = CFrame.new(pos,lookAt)
end)

This works as expected, but delivers a very unstable ‘wobbly’ camera position. This is because I am setting the camera relative to the HumanoidRootPart, which always moves by a tiny amount on the Y axis.
GIF URL: https://gyazo.com/ebd7832287424b369eefd409f028da5e

Is there anything I could do to fix this? I’ve tried rounding the Y property of the HumanoidRootPart down before processing, this leads to visible cuts when you ascend/descend.

The camera is pointing at the head which is animated, so naturally where the head is changes as well. Your camera points towards the head so it gets affected by the animation. The HumanoidRootPart, on the other hand, does not move because it’s not animated. Try making the HumanoidRootPart your lookAt instead of the Head, that should mostly rid of the wobbling.

1 Like

That’s a surprisingly easy fix! Thanks for the quick reply. It works as suggested, and the explanation also does make a lot of sense.