Help with recoil recovery maths

I’m having a bit of trouble figuring out how to implement clean recoil recovery. The code works perfectly fine, however how would I calculate the proper angle to reset the camera’s angle in the loop?

In the code example below, what would be the correct value that would reset the angle 0.2 to 0 over the span of LERP_TIME?

	if ViewModel_Tool then	-- if View model weapon was found
		if firingBool then
			Camera.CFrame = Camera.CFrame * CFrame.Angles(math.rad(10), 0, 0)	-- Intial recoil / jolt upwards
		end
		
		local current_time = 0	-- Recoil recovery using FPS independent lerp
		local LERP_TIME = 0.2
		while current_time < LERP_TIME do
			current_time += RunService.RenderStepped:Wait()
			Camera.CFrame = Camera.CFrame:Lerp(Camera.CFrame * CFrame.Angles(-math.rad(0.5), 0, 0),  math.min(current_time/LERP_TIME,1))
		end
	end
1 Like