I'm updating a value 60 percent closer to it's target value every frame using the formula a+(b-a)*alpha
. This works, but if someone has low frames it'll take longer to reach it's target.
local target = 4 local value = 0 local last = tick() while rs:wait() do local time = tick() local elaps = time - last value = value + (target - value) * .6 end
How can I modify this formula to use the elapsed time?
Oh that's simple, but completely silly.
The issue is that in this equation, you're missing a fundamental scale of when the tween is supposed to finish. Are we supposed to go there in 2 seconds? 2 minutes? It's all about that end goal.
local target = 4 local value = 0 local last = tick() while rs:wait() do local time = tick() local elaps = time - last last = time value = value + (target - value) * (1-0.6^elaps) end