Basic car gears with arrays (Advice please!)

I have a car which uses forces to move rather than wheels.

The game is not realistic, but I would like to create a gear system for my car.

I want to set an acceleration value and a top speed value for each gear, and be able to shift up and down gears.

I would think that using an array would be the best way to achieve this, however I’m not sure how to make it work.

I attempted it myself but I am pretty sure the way I tried it was not very good, and also was not working. I set up 2 arrays, one for each gears acceleration value and one for each gears topspeed. I planned to shift up and down both arrays at the same time. But i wasnt sure how to access the current gears values for both acceleration and topspeed.

Would anyone be able to offer advice on how to create this or where I could learn?

What I would do here is create a class that holds gear information. This class would contain the top speed and the acceleration of a gear:

[System.Serializable]
public class GearInfo
{
    public float acceleration;
    public float topSpeed;
}

In your vehicle controller script, you would then have an array of GearInfo and an integer that determines what gear the car is in:

public GearInfo[] gearInfo;
public int currentGear;

Lastly, in the FixedUpdate function, handle logic based on the gearInfo at the currentGear.

1 Like

That was so elegant. I appreciate your help so much. Thank you.