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

Engine Physics

This topic is 5008 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

What would be the ideal/easiest way to go about accelerating a car realisticly in a game world? What i have now is a an 1)equation to find force from the engine 2)equation to find accleration 3)equation to find out how much it moved in one Frame update How would i implement horse power and RMP into this mess. Equations would be helpful. Heres some of my code.
float CPhysics::AxleTourque(float GearRatio,float CrankShaftTourquefp,float TireDiameter,float DifferentialRatio)
	float Answer;
	FIRST = 3.37:1
	SECOND = 3.0:1
	THIRD = 1.56:1
	FORTH = 0.67:1
		Answer = ((GearRatio * CrankShaftTourquefp * DifferentialRatio)/(TireDiameter));
	return Answer;//Foot=Pounds at Axle


float CPhysics::AccelerateDist(float Gees,float Time)

	return ((16 * Gees) * (Time * Time));

float CPhysics::AccelerationForce(int Mass,float Force)
	float Answer;
	Answer = Force/float(Mass);
			return (Answer/9.8f);
		time = (time  + (1.0f/g_Render.FPS));//Add what part of a second each frame takes up

		MoveDist = g_Physics.AccelerateDist(

		MoveCar = (MoveCar - MoveDist);//Feet

		char TimeC[80];
		sprintf(TimeC, "Time: %f", time);  
if(MoveCar < -900.0f)//End Of Track RESET RACE

		Stage = STOP;
		TreeTime = 0.0f;
		time = 0.0f;
		g_Render.RaceEnd = true;
		MoveCar = 0.0f;
		Accelerate = false;
		FollowCarCam = false;
		g_Camera.PositionCamera(0.0f, 10.0f, 16.0f,   0, 10.0f, 0,   0, 1, 0);



Share this post

Link to post
Share on other sites
I am kinda lost on what you are doing. Here is the basic formulas.

Force = mass * Acceleration

Velocity Final = Velocity Initial + Acceleration * Time

This only works for steady velocities
x1=x0 + v*t;

So with these 3formulas your should have most of a basic car. So just use the time elasped between each frame.

Also here is where gravity comes in. 9.8 m / s*s... You can just apply it as a force.

a=9.8 m/s*s

F=9.8 * mass; And just have it poiting down and there you have gravity.

Ok but here is your basic stuff.

v+=a * (elasped time since last frame)

Thusly how far it moved is.
position+=velocity * (elasped time since last frame)

This is where the a=distance/(time * time) comes in. Since you eventually mutiply time twice for the final position.

So now you know how to update its position. But the main factor of a car is this crazy wind resistance (drag). For a game I would just keep it simple.

Drag=velocity*some coefficent;

This just means the faster you go the greater the force is pushing back. In the real world it isn''t so easy, but this work ok for most simple games.

Share this post

Link to post
Share on other sites
For a realistic acceleration, your engine should have a torque curve, like this: Torque=T(rpm), it can be a parabolic function for simplicity, or a lookup table for any curve.
But to have a more realistic acceleration, you should model the drivetrain of the car somehow, with gearbox ratioes, like in your code, and perhaps with clutch, and differential.

If you want to keep the air resistance simple, I suggest AirResistance = velocity*velocity*Coeff.

You should also include some friction in every part of the car: in the engine, gearbox, differential, wheels, like roll resistance.

Tell me, how complex simulation are you going to do. Because I have a lot resources, which could be useful in that case.

Share this post

Link to post
Share on other sites
If you want a good simulation, you should handle the different parts of a car as a rigid body, with their own motion, rotation equations (2nd Newtom law).
You have to apply the forces and torques to them. Perfect physics is too hard and time-expensive, so have to cheat somewhere, which simplifies the model, but doesn't influence much the result.
So the air resistance mainly effects the body opposite the velocity vector of the car, provided their is no wind
I don't know very much about aerodynamics. If it is so important, then look for some formulas with google. With a F1 game is really important. But with lower speed it become less important.

You also will have 4 wheel rigid bodies, which are attached to the body through a spring-damper with some constraints. Constraints are difficult to implement perfectly, so you can probably make some simplification in this area, using a simple suspension model, not double wishbone

The wheels get torque from the engine through the drivetrain. They also get torque form the road as a reaction torque when braking or accelerating, provided there is a contact.
The tyre model is very important, especially you turn or skid with your car. This is much more important than the engine. This can make the simulation realistic the most.
A tyre model usually has constants calculated from the tyre shape, radius etc. Beside that it uses variables as input data, like rotation rate, global velocity of the wheel, wheel's move direction in the wheels local coordinate system, camber angle, holding force. From these the well-known slip ratio and slip angle can be calculated.
The output of the tyre model is the longitudinal force, the lateral force and a moment for force feedback for example.
The widely used Pacejka tyre model has magic constants, which are calculated by measurments, so it's quite difficult to create a good constant set, because they are far from physics. A tyre model based on physics with physical constants is better (I mean easier to use) in my opinion.

So you should describe exactly what you want to do with your car. Is the car in the focus and is controlled by the user? Or is it just a background object. Will it be a car simulator? Etc.
After that I can help more: resources, equations.

[edited by - szinkopa on March 26, 2004 4:11:47 PM]

Share this post

Link to post
Share on other sites
There is another thread here about engine or so. I suggested a PDF there about driveline modelling.
And there are good links here:

Maybe you have not seen it.
You must study a lot of articles, and create your classes which represent the different parts of you car.
I suggest you creating a mini physics engine. Create abstract classes like CRigidBody, CInertia, CMass. These are the main objects. You will also need a SpringDamper class. then you connect the object together, apply some constraint with some cheat, create a Pacejka tyre model for example, and your first car is working
But it is not so simple, as I desribed. There are a lot of "obstacles".
You should firstly create your mini physics engine perfectly, which is an excellent base. It should contain a good RK2 or RK4 integrator. For representing orientation use the robust quaternion.
Test the physics engine with simple programs, like spring pendulum with a cube as rigid body or so to see if it works well.
You have to handle passive forces and torques (like sliding friction) well. Take this in account, when designing physics engine.

You probably want to solve collision detection. This is where I cannot help, because I haven''t implement it yet.

So come on, start reading docs...

Share this post

Link to post
Share on other sites