Spring based camera for car is jittery

This is what is happening with my camera(video)

I know it’s not the car because when using a fixed offset the camera smoothly follows.
I am using the implementation of the spring from the nevermore engine. I have tried setting the damper value to 1 (which I think is the critically damped option) but the same issue still occurs.

I am currently using this method of setting the desired camera CFrame. I have also tried separating the position and angle into separate components and updating each with a spring and another using CFrame.lookat using the cars lookvector and upvector but none of these produced a stable camera.

local function dc(cf: CFrame)
    local px, py, pz, 
        xx, yx, zx, 
        xy, yy, zy, 
        xz, yz, zz = cf:GetComponents()
    local p = Vector3.new(px, py, pz)
    local rv = Vector3.new(xx, xy, xz)
    local tv = Vector3.new(yx, yy, yz)
    local bv = Vector3.new(zx, zy, zz)
    return p, rv, tv, bv
end

local function CFrameFromTopBack(p, tv, bv)
    local right = tv:Cross(bv)
    return CFrame.new(p.x, p.y, p.z,
        right.x, tv.x, bv.x,
        right.y, tv.y, bv.y,
        right.z, tv.z, bv.z):Orthonormalize()
end

-- init
springs = {
            p = Spring.new(p),
            tv = Spring.new(tv),
            bv = Spring.new(bv)
        },

-- connected to render step
    local goalCF = target.CFrame * cameraSettings.CameraOffset
    local p, _, tv, bv = dc(goalCF)

    self.springs.p.t = p
    self.springs.tv.t = tv
    self.springs.bv.t = bv

    for _, spring in pairs(self.springs) do
        spring:TimeSkip(dt)
    end

    local finalCF = CFrameFromTopBack(self.springs.p.p, self.springs.tv.p, self.springs.bv.p)

    camera.CFrame = finalCF

This is the sections of importance in the code

Hopefully someone knows what’s going on because I am stumped.

Try using physics time instead of dt


RunService:BindToRenderStep("Camera",Enum.RenderPriority.Camera.Value + 3,function(dt)
      spring:update(self.lastDt) -- do update stuff
end)

task.spawn(function()
	while self._active do
		local tempTime
		tempTime, self.lastDt = RunService.Stepped:wait()
	end
end)

Would you mind telling me where did you get those codes from? oh and tell me how you use it as a module script? thanks! Edit: Welp they ignored me

1 Like

I originally did have the spring connected to RunService.Stepped(dt converted to seconds) but assumed this to be the cause of the jittering so moved to RenderStepped. I am a bit confused as to why a loop with a Stepped:Wait() inside is being used instead of just connecting directly to .Stepped to while loop fluff and a wait.

The cause of the jittering doesn’t really matter now as now I am just setting the camera subject to the car and the camera type to follow. I think the issue would boil down to solving for a critically damped spring so it doesn’t oscillate removing the weird jitter effect.

1 Like

Alright so I made two camera things based on your code, the only difference between the two of them is that one uses dt while the other uses Physics time.

This one is very jittery :frowning:

yay this one works

Ignore how ugly the map is I’m still testing some things so It’s more of a blueprint rn.