Jump to content
  • Advertisement
Sign in to follow this  

Calculate best car gear

This topic is 2125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I'm having some trouble trying to determine the best gear a car should be in to maximize acceleration.

I'm not looking for the perfect point at which to change gears to maximize acceleration.


I can get the current rpm of the car, the current speed, the current torque, optimal RPM's for gear ratios, engine torque for rpm, rpm from speed, and gear ratios.


I'm just not sure how to figure out what gear I should be in to get the best acceleration possible.


for example:

say I'm driving my car, I manage to shift all the way to 5th gear, going very fast. I suddenly crash, my speed reduces (but not to 0), I'm still in 5th gear. My acceleration now is very small, I should change gears, but to which gear in order to accelerate the fastest?


another example:

say I'm in 5th gear travelling very fast, I accidentally shift into 2nd, the rpm's rise quickly to the redline, my speed drops. What gear should I change into so that my engine doesn't explode and my acceleration will continue to increase?

Share this post

Link to post
Share on other sites
You could just search sequentially, trying each gear until the RPMs get close enough to where they should be. e.g.
if RPM < optimal_RPM-threshold and gear > 1
  gear --
if RPM > optimal_RPM+threshold and gear < max_gear
  gear ++

wait half a second for the engine to respond to new gear
Edited by Hodgman

Share this post

Link to post
Share on other sites

thanks for the reply. However, I'm looking at something that can give me an instant estimate.


The reason being that the gear is used as an indication/guide to the player so that they can change gears appropriately. 


The player needs almost instant feedback so they can make the required actions.

Share this post

Link to post
Share on other sites
The variable `gear' in Hodgman's code could represent the current recommendation, and the "wait half a second" can be skipped if it's not appropriate for what you have in mind.

Share this post

Link to post
Share on other sites

I ended up with something like this:

//find the current gear ratio
float currentRatio = gearRatios[currentGear];

if (currentRatio > 0) {

	float bestDist = float.PositiveInfinity;
	int bestGear = currentGear;
	int i, len = gears.Length;
	//start at index 2 (gear 1)
	//index 0 = reverse
	//index 1 = neutral

	for (i = 2; i < len; i++) {
		//find the gear ratio and the ratio to move into this gear from the current
		float gearRatio = gearRatios[i];
		float moveRatio = gearRatio / currentRatio;
		//find Optimal rpm. These are pre-calculated for each gear. They are generally around the redline mark (8000rpm for my car)
		float rpmOptimal = optimalRPM[i];
		//find the next rpm which the engine would produce if moving into this gear		
		float rpmNext = moveRatio * currentRPM;
		//find distance between optimal and next		
		float rpmDist = rpmOptimal - rpmNext;
		//if the next rpm is < maxRPM, the distance is above 0 (hasn't crossed optimal) and is < the current best, then this is a contender for the best gear

		if (rpmNext < maxRPM && rpmDist >= 0 && rpmDist < bestDist) {

			bestDist = rpmDist;
			bestGear = i;

So far it's working nicely. 

Edited by mr_malee

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!