Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Lerp animation completing before alpha is 1. Why? [Answered]

function Animation.TweenFoV(Zoom, Duration)
	spawn(function()
		local NewCode = math.random(-1e9, 1e9)
		
		FoVCode = NewCode
		
		local CurrentTime = 0
		local LastTime = tick()
		
		while true do
			if FoVCode ~= NewCode or CurrentTime >= Duration then break end
			local DeltaTime = tick()-LastTime
			LastTime = tick()
			CurrentTime = CurrentTime + DeltaTime
			
			local Alpha = CurrentTime/Duration
			
			if Alpha > 1 then Alpha = 1 end -- Make sure we don't go over.
			
			Camera.FieldOfView = Lerp(Camera.FieldOfView, Zoom, Alpha)
			
			RunService.RenderStepped:wait()
			print(CurrentTime)
		end
	end)
end

This loop should Tween the FOV of the camera to target "Zoom" in time "duration". When I run this code, the FOV will tween but not in the correct amount of time.

The FOV will equal Zoom in about half the time set by duration.

I don't see why this shouldn't work and work properly.

Edit: Here is my Lerp function.

function Lerp(Start, Finish, Alpha)
	return Start + Alpha * (Finish - Start)
end

4 comments

0

I have confirmed that Alpha = 1 when CurrentTime = Duration.

0

You're lerping the camera's FOV from the Current FOV, you should get that data and then put it in there (line 20)

0

Ah, I see now. Thank you!

0

That fixed it.

1 answer

✓ Accepted answer

As my comment solved the issue, mind accepting this answer so it falls under the answered tab? :D

(You're lerping the camera's FOV from the Current FOV, you should get that data and then put it in there (line 20))

1 comment

0

You should include your answer in this Answer, for completeness

This discussion is preserved as it was. New answers, comments, and votes are closed.