I think there was a function to do this, but I forgot what it was called.
I think you can just get a variable as a number and keep dividing it by annother number.
Ex:
Local var = 2
var += var / 2
local value = 0
local rate = 0.1
while true do
value = value + rate * (1 - math.exp(-value))
wait(1)
end
This needs a way to break the loop just an example.
if value >= ? break
better yet:
while value < ? do
You could use the math.log(value+1) function since as you can see on this image the higher the value (x) is, the slower it raises. We add the 1 so you don’t get negative output with lower inputs.
What website is that image from?
This is what I use, can definitely recommend.
Hey OP. I know this has already been solved but the logarithmic solution won’t necessarily ensure that the value never gets larger than a certain value. I’m not sure if you’ve taken calculus, but you will find the limit of the logarithm function is infinity, which means the logarithm never truly stops increasing for a sufficiently large input. You could use math.clamp
, but that leaves desire for something better.
If you want the value to increase up to a certain value (and more control over how quickly your value begins to slow down), consider the asymptotic form:
f(x) = ax / (x + n)
where a
is the maximum value you desire and n
is how slow you want f(x)
to scale (a larger n
means that f(x)
takes longer to approach its horizontal asymptote/maximum value).
Here is what that function looks like for a
= 1 and n
= 5:
As you can see, f(x)
(the purple line) is approaching a value of 1 (the dashed line) but decreasing as it does so. It will never truly become 1 (well, it will because floating point isn’t 100% precise) but it will give you the slow-down you desire.
Just an alternative suggestion, in case you desire slightly different behavior.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.