Hi again everyone,
I have a small racing game that is near complete, but I have noticed some odd behaviour recently… when you run it in the faster graphics modes, the acceleration and braking increases a LOT and renders the game almost unplayable. I figure this is down to my use of Time.deltaTime… I obviously want the game to run exactly at the same speed, no matter what machine it is running on. Where am I going wrong? Cheers!
if (!bCarDestroyed)
{
// If W key is pressed, accelerate
if (Input.GetKey("up") && g_fSpeed < g_fMaxSpeed || Input.GetButton("GasP1") && g_fSpeed < g_fMaxSpeed)
{
g_fSpeed += g_fAcceleration;
transform.Translate(0.0f, 0.0f, g_fSpeed * Time.deltaTime);
}
// If S key is pressed, brake
else if (Input.GetKey("down") || Input.GetButton("BrakeP1"))
{
// Disable boost
g_bBoostEnabled = false;
if (g_fSpeed > 0.0f) // Brakes only work if car is moving
{
g_fSpeed -= fBrakeForce;
transform.Translate(0.0f, 0.0f, g_fSpeed * Time.deltaTime);
}
}
// If no input, slow down gradually
else
{
if (g_fSpeed > 0.0f) // So that car doesn't move in reverse when comes to stop
{
g_fSpeed -= fDecceleration;
transform.Translate(0.0f, 0.0f, g_fSpeed * Time.deltaTime);
}
}
}