I’ve recently discovered that the function TweenService uses for Enum.EasingStyle.Exponential
does not approach 1, which results in rough jumps at the end of tweens, particularly when tweening the camera large distances.
It approaches 0.9990234375
, which you can easily see just by running the following command in the console:
print(game.TweenService:GetValue(0.9999999, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out))
As a workaround, I made the following function for Exponential which roughly approximates the curve but approaches 1 exactly:
function fixedExponential(t, dir)
t = math.clamp(t, 0, 1)
if dir == Enum.EasingDirection.In then
return math.pow(2, math.pow(t, 4.985)) - 1
elseif dir == Enum.EasingDirection.Out then
return 2 - math.pow(2, math.pow(1 - t, 4.985))
elseif t < 0.5 then
t *= 2
return (math.pow(2, math.pow(t, 4.985)) - 1) * 0.5
else
t = (t - 0.5) * 2
return (2 - math.pow(2, math.pow(1 - t, 4.985)) * 0.5) + 0.5
end
end
While the above workaround works in scenarios where I just need an interpolation value, the Tweens from TweenService:Create()
still use the incorrect function, which means they have a slight (but very visible) jump/stutter at the end.
Expected behavior
I’m expecting all functions from TweenService to approach exactly 1 in order to be smooth in all scenarios. If you run the above command with the other EasingStyles, they all return 1 (or very close to it); Exponential is the only style which approaches a different value.