Hello everyone. I need some help. I have followed ‘FlatTutorials’ videos on how to make a car game.
Here is the code:
// If speed limiter is on, disable speed when we hit top speed.
if (currentSpeed >= topSpeed && speedLimited == true && !handbrake){
wheelRR.motorTorque = 0;
wheelRL.motorTorque = 0;
}
else if(!handbrake) {
// This is where the power is applied to the wheels
wheelRR.motorTorque = engineTorque * Mathf.Clamp(Input.GetAxis("Vertical"),-1,1);
wheelRL.motorTorque = engineTorque * Mathf.Clamp(Input.GetAxis("Vertical"),-1,1);
if (!Input.GetAxis("Vertical")){
wheelRR.brakeTorque = 30;
wheelRL.brakeTorque = 30;
}
else {
wheelRR.brakeTorque = 0;
wheelRL.brakeTorque = 0;
wheelRR.brakeTorque = brakeTorque * -1 * Mathf.Clamp(Input.GetAxis("Vertical"),-1,0);
wheelRL.brakeTorque = brakeTorque * -1 * Mathf.Clamp(Input.GetAxis("Vertical"),-1,0);
}
}
I have a problem though - when I go up slopes, my car speeds up a lot and it’s very unrealistic.
If anyone has a solution I would be very grateful.