Flickering when detecting the change in velocity

I’m making a movement system, and i want to detect the change in velocity and use that to change the FOV, but it flickers ALOT when just going straight. what am i doing wrong and how can i fix it / make it less noticeable?

video of what the flickering looks like:

code:

function Renderfunc(Delta) -- run for visual stuff
	totvel = math.abs(Char.AssemblyLinearVelocity.X) + math.abs(Char.AssemblyLinearVelocity.Z)
	cam.FieldOfView = 75 + (((totvel - prevtotvel))*5) -- *5 added to make the flickering more noticeable in the video
	prevtotvel = totvel
	-- some code removed, none that effect this
end

I’m pretty confused what might be causing this, and tried using delta to fix it but with no avail ;p

Don’t just take my word for it, but using lerping could be helpful. The best-case scenario would involve trial and error.

local smoothness = 0.1

function Renderfunc(Delta)
	totvel = math.abs(Char.AssemblyLinearVelocity.X) + math.abs(Char.AssemblyLinearVelocity.Z)
	prevtotvel = totvel
	
	-- Smoothly transition to the target FOV
	cam.FieldOfView = cam.FieldOfView + ((75 + ((totvel - prevtotvel) * 5) - cam.FieldOfView) * smoothness
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.