#### Archived

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

# Engine Physics

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

## 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)
{
/*
FIRST = 3.37:1
SECOND = 3.0:1
THIRD = 1.56:1
FORTH = 0.67:1
*/
Answer = ((GearRatio * CrankShaftTourquefp * DifferentialRatio)/(TireDiameter));

}

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

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

float CPhysics::AccelerationForce(int Mass,float Force)
{
}

	if(Accelerate)
{
time = (time  + (1.0f/g_Render.FPS));//Add what part of a second each frame takes up

MoveDist = g_Physics.AccelerateDist(
(g_Physics.AccelerationForce(
3500,g_Physics.AxleTourque(3.37f/*Gear*/,102.0f/*TorqueOutput*/,25.0f,3.27f)))
,time);

MoveCar = (MoveCar - MoveDist);//Feet

char TimeC[80];
sprintf(TimeC, "Time: %f", time);
glPushMatrix();
glColor3f(0.0f,1.0f,1.0f);
glTranslatef(-10.0f,10.0f,-10.0f);
glDraw3DText(TimeC);
glPopMatrix();
}
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);
}
DrawCars();
DrawTachameter();
DrawDragTree();

if(g_Render.RaceEnd)
RaceResults();

}


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

Force = mass * Acceleration
F=ma

Velocity Final = Velocity Initial + Acceleration * Time
v1=v0+at

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.

a=F/m
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 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 on other sites
Yup sorry, drag is velocity squared...

edit: forget the d on squared hehe

[edited by - JimmyNelson on March 25, 2004 7:46:42 PM]

##### Share on other sites
I just want it to be realistic

now with the air resistance how do i take that and put it into my overall equation to affect the cars movement?

##### 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 on other sites
Im trying to create a drag racing simulator.

I have all the pieces of the world put together and the basic logic.

Now all i need is the physics.

##### 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...

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 12
• 10
• 13
• 104
• 11
• ### Forum Statistics

• Total Topics
632979
• Total Posts
3009683
• ### Who's Online (See full list)

There are no registered users currently online

×