Help with Car Tutorial

Could someone explain what’s happening in this Car Tutorial. I know it’s increasing by increments of one. I’m not understanding this. Sorry I’d like to be more clear. The shifting of the gears increments up one gear, you’re dividing by 4 because there are 4 gears, but why are we adding the gear speed with an array argument of [i-1]. Are we shifting up almost as a default and if > shifting down?

Thanks in advance!!!

function SetupGears()
{
engineForceValues = new float[numberOfGears];
gearSpeeds = new float[numberOfGears];

var tempTopSpeed : float = topSpeed;

for(var i = 0; i < numberOfGears; i++)
{
if(i > 0)
gearSpeeds = tempTopSpeed / 4 + gearSpeeds[i-1];

  • else*
    _ gearSpeeds = tempTopSpeed / 4;_

* tempTopSpeed -= tempTopSpeed / 4;*
* }*

* var engineFactor : float = topSpeed / gearSpeeds[gearSpeeds.Length - 1];*

* for(i = 0; i < numberOfGears; i++)*
* {*
var maxLinearDrag : float = gearSpeeds * gearSpeeds_;// * dragMultiplier.z;
engineForceValues = maxLinearDrag * engineFactor;
* }
}*_

The car has a range of speeds between standstill and the top speed, whatever it is set to. Each of the car’s gears covers a certain range of speeds, so say first gear might be 0-20mph, second might be 20-35mph, etc. The first time round the loop, first gear is set to cover a quarter of the speed range. Each subsequent gear covers a quarter of whatever is left. So if the top speed were 80mph, first gear would operate up to 20mph. Then, second gear operates over a quarter of the remaining 60mph range between 20 and 80, so it would have a 15mph range. However, to record the speed at which a given gear tops out, you have to add the top speed of the previous gear. This is the origin of gearSpeeds[i - 1], the speed of the gear one element back in the array.