We are game developers currently working on a new game. We are looking to solve the following problem:
We start with the following variables:
$x = 0, h = 1;$
The variable x should always increase over time depending on $h$—the larger the $h$ the larger the rate that $x$ increases. On the other hand $h$ decreases over time with a steady velocity. $h$ ranges from 0 to 1.
After time $t$ the variable $x$ will become:
$x := x + \sum( C_1 \cdot ( h + V \cdot n ) ) \mathrm{\ for\ } n = [0, t]. $
$C_1$ is a constant. $V$ is the change rate of $h$.
Whenever we calculate $x$ we need to calculate the new value of $h$ like so:
$h := h + V \cdot t$
So what happens in order is this:
- $x := x + \sum( C_1 \cdot ( h + V \cdot n ) ) \mathrm{\ for\ } n = [0,t]$
- $h := h + V \cdot t$
Both of these formulas could be wrong of course, this is simply what we are trying to achieve.
The variable t is essentially time in seconds. The problem is that if say $t = 2$ then $x$ will have a certain value if we calculate it like so:
- $x := x + \sum( C_1 \cdot ( h + V \cdot n ) ) \mathrm{\ for\ } n = [0,2]$
- $h := h + V \cdot 2$
and a different value if we calculate it like so:
- $x := x + \sum( C_1 \cdot ( h + V \cdot n ) ) \mathrm{\ for\ } n = [0,1]$
- $h := h + V \cdot 1$
- $x := x + \sum( C_1 \cdot ( h + V \cdot n ) ) \mathrm{\ for\ } n = [0,1]$
- $h := h + V \cdot 1$
Essentially the values are different if we break up the calculation into more steps.
We need the values to be the same in both cases. We cannot do this with these formulas so I was wondering if there is another way to do this. I understand that my explanation might be a little difficult to understand but it's not very easy for me to explain this!
Thank you