Camera bobbing dependent on FPS

Title explains the issue. My camera bobbing uses springs to work and so far I’ve always multiplied it by deltatime.

Multiplying it by deltatime does not fix the issue:

-- inside renderstep

-- dt = deltaTime
springs.walk:shove((bob / config.bobDivisor) * dt * 60 * velocity.Magnitude)
springs.camera:shove((camBob / config.camBobDivisor) * dt * 60 * velocity.Magnitude)

I’ve also tried this, (it did not fix it)

local totalTime = 0
local stepTime = 1/120

function renderStep(dt)
 totalTime = math.min(totalTime+dt,1)
 while totalTime > stepTime do
  -- also tried with and without dt*60
  springs.walk:shove((bob / config.bobDivisor) * velocity.Magnitude)
  springs.camera:shove((camBob / config.camBobDivisor) * velocity.Magnitude)
totalTime-=stepTime
 end
end)

I’ve also tried different equations for scaling on deltatime, none worked:

  1. 1-math.exp(-x*dt)
  2. dt / (1/60)

Every devforum post I saw did not solve my issue, even when using springs.

tl;dr

bobbing speed and size using springs is dependent on fps when scaling by deltatime
i need it to be the same on all fps values

1 Like

Try adding the scalar equation after your magnitude variables as well, it should be at the end of the equation IIRC.

Also, are you using spring:update(dt) to update your spring accordingly?

2 Likes

didn’t change anything.

-- also tried putting dt*60 at the end same result

local n = 1-math.exp(-100*dt)
	
-- spring shoving
springs.walk:shove((bob / config.bobDivisor) * velocity.Magnitude * n)
springs.camera:shove((camBob / config.camBobDivisor) * velocity.Magnitude * n)
springs.sway:shove(newVector3(0, -(mouseDelta.x / config.swayDivisor), mouseDelta.y / config.swayDivisor)) -- dont think this needs to be scaled with dt

-- spring updates
local modelSpring, swaySpring, camSpring, walkSpring, modelRotSpring =
		springs.model:update(dt), springs.sway:update(dt), springs.camera:update(dt), springs.walk:update(dt), springs.modelRot:update(dt)

-- this is how i set the cframes (very hard to read)
	camera.CFrame = camera.CFrame * newAngles(camSpring.x,camSpring.y,camSpring.z) * camRoll
	viewmodel:PivotTo(camera.CFrame * newCFrame(walkSpring.x+modelSpring.x, modelConstantOffset.Y+walkSpring.y+modelSpring.y, modelConstantOffset.Z+modelSpring.z+walkSpring.z) * newAngles(modelRotSpring.x+walkSpring.x+swaySpring.x,modelRotSpring.y+swaySpring.y+walkSpring.y,modelRotSpring.z+swaySpring.z) * modelOffsetLerp)

I think so

Are you attempting to prevent excessive or insufficient movement?

I can’t really tell based on the video, but if you are preventing insufficient you should be dividing your equation by the DeltaTime operand.

While I wait for your answer I’ll continue to investigate why this is happening, however I believe this may be the solution.

1 Like

you’re shoving the spring every frame which would shove the springs more or less depending on how many frames per second there are. is there any way of setting a “target” for the spring of sorts?

2 Likes

Yeah i figured it out,
Just used this to run :shove at a consistent rate.

I think its working atleast…

1 Like