Original Post
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);
}
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();
}