I am making a game, and controlling a character's velocity.
The game works by updating the character's velocity 60 times per second.
At each frame, I do this:
"set new velocity to current velocity + accelerationRate * (maxVelocity - currentVelocity)"
I wrote this out as this series equation (I think that's what this is called, if not please let me know). To simplify I'm using my accelerationRate as .2 and the maxVelocity as 800.
$$a_n = a_{n-1} + .2 * (800 - a_{n-1})$$
So as a series that starts at 0, I'd have:
0, 160, 288, 390.4, 472.32
for my first 5 values.
So I have a few questions:
- What is my $a_n$ equation called? Is that a "series equation"?
- How do I solve for the nth term?
- How do I rewrite this as a sum and/or as an exponential function?
Thanks.. I am really rusty on this.. Sorry for abusing terminology here
Are you playing in 1D? If so, you are a flop. If not, you need to consider velocity in two dimensions. Now you need velocities in two directions.
As columbus says, you can write your equation as $a_n=0.8a_{n-1}+160$ This is an inhomogeneous recurrence relation If you set $b_n=a_n-800$ it becomes $b_n=0.8b_{n-1}$, which is homogeneous. The solution is $b_n=0.8^nb_0$, so the solution to the original equation is $a_n=0.8^n(a_0-800)+800$