#### Archived

This topic is now archived and is closed to further replies.

# Realistic Car Acceleration?

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

## Recommended Posts

I was just wondering how to make my car accelerate at a realistic speed, eg. accelection slowing down as it approaches the top end speed etc... I''ve looked at a few car physics tutorials but they didn''t shed much light on the matter. Any help would be greatly apreciated.

##### Share on other sites
Lets say you already have your force from the engine accelerating the car fowards. If you just had this force, your car would carry on accelerating forever. Now you want to add air resistance. Air resistance is a force going backwards, and is proportional to the square of your fowards speed. So, the faster you go, the air resistance gets bigger and bigger, until eventually the air resistance balances the foward force and your cars speed levels out. Ofcourse that model isn''t totally accurate (you may wish to add the rolling resistance of the tyres, account for changes in torque due to gear shifts, etc.) but including air resistance will make the model a whole lot more realistic for only a little coding time.

Air resistance = -(Speed ^ 2) * Constant

which you may want to optimise to

Air resistance = -(Speed * Speed) * Constant

##### Share on other sites
Thanks, but I''m not quite sure how to work out the force applied by the car. I know its along the lines of:

Engine Torque * Gear Ratio * Differential Ratio

I had a method similar to this in my little game, but it was still fake because the way I calculated the Torque used the RPM, and the RPM was calculate simply as RPM+=10 when the up arrow was pushed Giving a constant acceleration, which isn''t true because as we see when driving a car (and playing game) the closer you get to the redline of the enigine the slower the RPM increases.

So I''m not quite sure how to go about it?

##### Share on other sites

edit: Don't miss the links at the bottom, they also look quite good.

[edited by - MisterAnderson42 on August 31, 2002 10:50:37 PM]

##### Share on other sites
Yeah, I''ve looked at that site but I couldn''t understand something about it. They say you need the RPM to calculate the torque, but you need to know the torque to calculate the RPM? Its probably that I''ve just missed something, or didn''t understand it properly?

##### Share on other sites
Welcome to the world of Differential equations, where the speed can depend on the acceleartion, and at the same time the acceleration depends on the speed (I''m thinking of air resistance). Solving equations like these symbolically can be quite difficult if the equation is complex. Though, from the standpoint of a coder using discrete timesteps to calculate the position, it is no different from doing the normal laws of motion.

For cars, assuming no torque converter or clutch, the RPM of the engine is directly related to the cars speed and the current transmission gear ratio, right? Everything is physically connected. So your engine RPM is given for you by that. Now, you have a table of the torque that the engine can supply at a given RPM. Depending on the throttle position, supply some fraction of that torque to the transmission, which gears it down, applying it to the wheels, which apply a force to the road. Now, this force will make the vehicle accelerate, and you can now calculate, position and speed for time t+1. Now, the change in speed will affect the RPM of the engine. BUT.. don''t worry about that at time t (it will be obviously be taken into account at time t+1). We just pretend for the sake of approximation that the RPM doesn''t change at all during time t.

##### Share on other sites
A quick and dirty cheat would be to simply multiply the velocity of the car by say 0.9 at each timestep. Adjusting this number will change the maximum achievable speed. You''ll probably need to adjust the applied acceleration force as well in order to get a realistic feeling.

##### Share on other sites
quote:
Original post by MisterAnderson42
Welcome to the world of Differential equations, where the speed can depend on the acceleartion, and at the same time the acceleration depends on the speed (I''m thinking of air resistance). Solving equations like these symbolically can be quite difficult if the equation is complex. Though, from the standpoint of a coder using discrete timesteps to calculate the position, it is no different from doing the normal laws of motion.

For cars, assuming no torque converter or clutch, the RPM of the engine is directly related to the cars speed and the current transmission gear ratio, right? Everything is physically connected. So your engine RPM is given for you by that. Now, you have a table of the torque that the engine can supply at a given RPM. Depending on the throttle position, supply some fraction of that torque to the transmission, which gears it down, applying it to the wheels, which apply a force to the road. Now, this force will make the vehicle accelerate, and you can now calculate, position and speed for time t+1. Now, the change in speed will affect the RPM of the engine. BUT.. don''t worry about that at time t (it will be obviously be taken into account at time t+1). We just pretend for the sake of approximation that the RPM doesn''t change at all during time t.

How would the car accelerate using that method? I''m probably wrong, but as I see it you are calculating the RPM of the current speed of the car, and then using that to set the new speed in the car. So wouldn''t the RPM just stay the same the whole time?

##### Share on other sites
[*quote]Air resistance = -(Speed * Speed) * Constant

as Bazee said is not entirely true.

If your car can go backwards, it will have a negative speed value so squaring this you would lose the sign..
here''s a macro for ya
SQRMAG(x) x>0? x*x : x*-x

J.

return(0);

##### Share on other sites
quote:
How would the car accelerate using that method? I'm probably wrong, but as I see it you are calculating the RPM of the current speed of the car, and then using that to set the new speed in the car. So wouldn't the RPM just stay the same the whole time?

Think about it. Use the current RPM to update the speed (because the engine can apply a torque which eventually becomes a force on the road). Since the engine and tires are mechanically linked (ignoring clutch and torque converter) and each turn together, you can find the new RPM of the engine given this new speed. This will be used in the next timestep to find the available torque again.

quote:
If your car can go backwards, it will have a negative speed value so squaring this you would lose the sign

Correct. More formally, air resistance is a frictionaly force which always opposes motion. So, it has maknitude k * speed**2, and direction -V hat, where V hat is the velocity unit vector. In full vector notation: Fa = k * (V dot V) * (-)(V / ||V||)

[edited by - MisterAnderson42 on September 2, 2002 10:28:39 AM]

##### Share on other sites
Original post by MisterAnderson42
quote:

Think about it. Use the current RPM to update the speed (because the engine can apply a torque which eventually becomes a force on the road). Since the engine and tires are mechanically linked (ignoring clutch and torque converter) and each turn together, you can find the new RPM of the engine given this new speed. This will be used in the next timestep to find the available torque again.

Ahhhh, its finally hit me, Thanks for putting up with me Now, Does anyone know where to get information about how much torque a car puts out at a given RPM :D.

P.S Thanks for the tip with the negative sign for Air Resistance.

[edited by - FlorianapoliS on September 3, 2002 8:37:21 PM]

[edited by - FlorianapoliS on September 3, 2002 8:57:19 PM]

##### Share on other sites
Google it out. I think the graph is sometimes called "horsepower graph". It shouldn''t be difficult to find a few examples.

I easily found the graph for the Audi S4:
http://www.autospeed.com/image.html?A=0514&P=1&IMG=0514_3&REZ=hi&LOC=%2Fimages

##### Share on other sites
Is that graph for only one gear, or is it the same through out all the gears?

##### Share on other sites
It''s characteristic of the engine, so it''s the same for all the gears.

Ahhh, thanks

##### Share on other sites
quote:
Original post by cultofpurplecabbage
[*quote]Air resistance = -(Speed * Speed) * Constant

as Bazee said is not entirely true.

If your car can go backwards, it will have a negative speed value so squaring this you would lose the sign..
here''s a macro for ya
SQRMAG(x) x>0? x*x : x*-x

J.

return(0);

Speed is the magnitude of the velocity. Magnitude is never negative, since it''s the positive square root of the sum of the squares of the components of the vector.

Your macro also has a few flaws... e.g.
SQRMAG( 2 + 2 ) = 8

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

##### Share on other sites
I was just wondering if there is anyway of generating torque curves for certain engines? Because currently I would have to enter a couple of hundred values into an array manually, and it would be quite pain staking.

##### Share on other sites
You could always interploate. 5-10 values with interpolation should be enough to generate something that works well for a game.

##### Share on other sites
Thanks,I''ve made a little VB program that fills in the blanks when I give it values Its just that now I have another problem, I''ve got the car accelerating, but it tops at out 36km\h in 6th gear at 6500rpm?

My drag constants.

  const float CDrag = 0.4257f;const float CFric = 12.8f;

(Ignore the corvette, its actually for the Audi S4) These are my car properties.

  	corvette.cartype.WheelBase = (float)4.4f;	corvette.cartype.GearRatio[1] = 3.500f;	corvette.cartype.GearRatio[2] = 1.889f;	corvette.cartype.GearRatio[3] = 1.230f;	corvette.cartype.GearRatio[4] = 0.967f;	corvette.cartype.GearRatio[5] = 0.806f;	corvette.cartype.GearRatio[6] = 0.684f;	corvette.cartype.Diff = 4.4f;	corvette.cartype.Mass = 2100;	corvette.cartype.WheelRadius = 0.45f;

And my move car function:

  int MoveCar(CAR &car, float delta){	float max_torque, engine_torque, drag, friction;	max_torque = car.cartype.Torque[(int)car.rpm]; //Get max torque at a given RPM	engine_torque = max_torque * (car.throttle / 100); //Multiply it by throttle position		drive_force = engine_torque * car.cartype.GearRatio[(int)car.gear] * car.cartype.Diff * corvette.cartype.WheelRadius * 0.7f; //Calculate drive force	drag = - CDrag * car.vel * ABS(car.vel); //Calculate Drag	friction = - CFric * car.vel;	//Calcualte Friction 	car.force = drive_force + drag + friction;	//Find sum of forces acting on car	car.accel = car.force / car.cartype.Mass;	//F = m / a, to find acceleration	car.vel = car.vel + car.accel * delta;	//calculate car velocity using v = u + at	car.rpm = ((car.vel / corvette.cartype.WheelRadius) * car.cartype.GearRatio[(int)car.gear] * car.cartype.Diff * 60) / 2 * (float)PI; //Workout RPM off new speed, for next set of calculations	if (car.rpm < 1000) //Make sure RPM doesn''t go under engine idling RPM		car.rpm = 1000;	return 1;}

If anyone could point what is causing my car to top out at such a low speed it would be a great help.

##### Share on other sites
Just a thought... do you ever shift gears? I don''t see anything overtly wrong with the code you give. Maybe you could play with constants, like turn off air resistance and see how that affects things.

##### Share on other sites
Yeah, currently it''s a manual I think I''ll try some different car info as well.