Jittery camera using a spring service

Hello, I am trying to make the player’s camera smoothly follow the character. I got it working but the result is jittery (please watch the video below). The spring service I am using is from Quenty’s NevermoreEngine.

Here is the script that I made

local Configuration = {
	SmoothFollow = {
		Damper = 1.8,     -- Damper value for the spring
		Speed = 15        -- Speed of the spring
	}
}

RunService:BindToRenderStep("SmoothFollow", Enum.RenderPriority.Camera.Value + 1, function(DeltaTime)
	local Freecam = Player:FindFirstChild("FreecamEnabled")
	
	if Freecam and Freecam.Value == true then
		return
	end
	
	CameraSpring.Damper = Configuration.SmoothFollow.Damper
	CameraSpring.Speed = Configuration.SmoothFollow.Speed
	CameraSpring:SetTarget(Camera.CFrame.Position)
	
	local CameraPosition = CameraSpring.Position
	local CameraRotation = Camera.CFrame - Camera.CFrame.Position
	Camera.CFrame = CFrame.new(CameraPosition) * CameraRotation
end)

Any help would be appreciated, thank you :grinning:

3 Likes

Interesting problem, normally I see people using :Impulse() rather than set target. Perhaps it’s because set target is updating the position discretely which is not smooth?

What if you were to change the order? get the position first and then set the target.

	local CameraPosition = CameraSpring.Position
	local CameraRotation = Camera.CFrame - Camera.CFrame.Position
	Camera.CFrame = CFrame.new(CameraPosition) * CameraRotation

	CameraSpring:SetTarget(Camera.CFrame.Position)

If it doesn’t work then you could try the impulse method setting the position to 0,0,0 and impulsing it based on the position change of the root part.

3 Likes

Thank you for replying to this post :smiley:

What if you were to change the order? get the position first and then set the target.

I actually have tried this before I made this post and unfortunately for me it didn’t work.

If it doesn’t work then you could try the impulse method setting the position to 0,0,0 and impulsing it based on the position change of the root part.

I tried implementing this but I somehow couldn’t get it to work…?

2 Likes

I have the same problem with that module, I made a post about it today. And it’s even more jittery if you add a body velocity the character. Hopefully @Quenty or someone else who uses this module can help us fix this problem because this module is working great to get my desired camera position but the laggy effects ruins it.

1 Like

Have you tried using heartbeat instead? It might be from the spring’s goal being changed sporadically because the character’s position is being updated on heartbeat, while the spring’s position is being changed with the camera’s update.

You can check out this video at the timestamp I set from some great devs (including Quenty):

It has some working code for camera following that uses heartbeat instead.

Edit:

I think because of the way you’re getting the CFrame (by updating the default camera after it calculates it’s goal position) you could:

  • Have one loop on heartbeat to update the goal based on the camera position
  • Have another one unit after the camera update to update the camera based on the spring being updated on heartbeat
2 Likes