How can I calculate "dynamic" exponential rates?

llmu

New member
Joined
Apr 22, 2021
Messages
3
I hope this is the right category.

I'm programming a game and came up with some problems I could solve with some built-in functions but decided to try and understand the logic of how the formula would look like and work.

So what I wanted to achieve is going from 0 to 50 exponentially in 5 steps, what I mean by steps is the amount of times its required to add to the starting value in order to reach the target value 50.

Ideally I would be able to adjust the ramping of the "curve" so it starts adding more on the first steps and less at the end or the opposite.
The important part is that the target value must be the exact value or finitely close. How could I achieve this using mathematics? I hope the idea gets through even with all the, probably wrong, terminology I used.
 
I hope this is the right category.

I'm programming a game and came up with some problems I could solve with some built-in functions but decided to try and understand the logic of how the formula would look like and work.

So what I wanted to achieve is going from 0 to 50 exponentially in 5 steps, what I mean by steps is the amount of times its required to add to the starting value in order to reach the target value 50.

Ideally I would be able to adjust the ramping of the "curve" so it starts adding more on the first steps and less at the end or the opposite.
The important part is that the target value must be the exact value or finitely close. How could I achieve this using mathematics? I hope the idea gets through even with all the, probably wrong, terminology I used.
Please explain what you mean by "exponential". I don't think it means what you think it means. (An exponential function can never be zero.)

Possibly you mean that the steps should be a geometric sequence.
 
Please explain what you mean by "exponential". I don't think it means what you think it means. (An exponential function can never be zero.)

Possibly you mean that the steps should be a geometric sequence.

Thanks for the reply and you are right the first step can't be 0. About the geometric sequence If it is what I know for lineal increase then no, it is not what I'm looking for.

Ideally I just use a number and this number would be increasing "exponentially" if understand correctly and hitting an specific number after x number of steps in my example 5.
so the first value can be whatever in between but my idea is to make an easing formula that start adding small quantities and ramps up as the steps get closer to the fifth step.

This is a terrible example but the result should look something like: 10,12,20,30,55. So I would like a formula that given an specific "rate" or value gives me each step's value and on the last step hits the exact target value. And if there's an easy way to adjust if the steps are easing out or easing in.
This website showcase different types of curves: https://easings.net/ Some of these are much more complex than what I actually want to achieve I want to achieve something like the Cubic easing.


For a more specific explanation:
In game what I'm trying to achieve is that when the player drops below a threshold lets say 45% of their maximum health and the maximum health is 100. The player will heal every turn, what I previously refereed as steps, the amount of health restored should be a ramp up number and on the last turn of the effect, after 5 turns. The amount of healing should be equal to 55% of the maximum health the amount of health above the threshold.

The way I wanted to do this was to get every turn a number between 1 and 55. Divide the step value by 100 and multiply it by the players maximum health this would create an increasing healing based on the players maximum health but capping the maximum amount to only 55% of the players maximum health.
 
Last edited:
I got it.
What I needed was a quadratic function.
target value = square root (55)
initial value = target_value - number of steps (5)
every step adds 1 to the initial value and this initial value is multiplied by itself.

results:
1: 11.670412
2: 19.502809
3: 29.335206
4: 41.167603
5: 55

If there's a easier or more refined way to achieve this let me know.
 
I don't think you have any idea what exponential means; but if you mean that the increase itself should be increasing by the same amount, then yes, that would be a quadratic function.
 
You have no idea what the words you use mean.

Let’s if we can try to put what you mean into English and then into math. Using a bunch of mathematical terms with meanings you do not know is not going to get us very far.

My guess at an English translation is as follows

You have a game where characters have a degree of health measured in integers. Zero means dead, and 100 means maximum possible health. If a character‘s health falls to i in some period, where 0 < i < 55, you want the character‘s degree of health to increase by increasing amounts period by period until, after five periods, the degree exactly equals 55.

First, is it true that you want integer answers? If not, how many decimals do you want? I suspect that this issue is why you said “finitely close” in your first post. I am going to assume that you are dealing with integers, but it makes no fundamental difference because computers do not have an infinite number of bits nor fractional bits.

Second, what you are asking for is literally impossible. Here is an easy example working with integers. The initial value is 54. Is it not obvious that you cannot go from 54 to 55 in five steps of integers. You will need to decide what to do with initial values that are “close” to 55.

Third, there are an infinite number of ways to solve this problem. We cannot reverse engineer what way your tool uses without numerical examples.

Here is ONE very easy way to program the kind of thing you MAY want.

Initially set t, meaning time to cure, at 0.

When you lower a, someone’s actual degree of health, below 55 but above 0, set t = 5 and set i, meaning incremental health improvement, =

[MATH]\dfrac{55- a}{31}.[/MATH]
Then at later steps, do

If t = 0, skip to NEXT

Subtract 1 from t.

Compute new actual health value, as follows

If t = 1, set a = 55.

If t > 1, you add to a an amount = [MATH]\lfloor i \div 2^t \rfloor.[/MATH]
NEXT

Let‘s see how that would work.

If you lower to 10, then i = 35. In period 1 of cure, you would go up from 10 to 12. In period 2, you would go from 12 to 16. In period 3, you would go from 16 to 24. In period 4, you would go from 24 to 40. In period 5, you would go from 40 to 55. Until period 5, the increases are doubling each period.

What happens if you lower to 46 initially under this algorithm.

You would stay at 46 until period 3, when you would go to 47. Then you would go to 49 in period 4. And 55 in period 5.

To summarize. With any initial value in excess of 39, the earliest periods will show no improvement. Provided improvement starts before period 4, the degree of improvement will double each period after the period when improvement starts until the fifth period, which will take the improvement to 55.

You could get fancier with different formulas. But you have to be clear on what you want.
 
Last edited:
Top