- Home /
Different top speed when going downhill
Hello!
I need my car to have a different top speed when going downhill. How do I implement this?
public WheelCollider wheelFL;
public WheelCollider wheelFR;
public WheelCollider wheelBL;
public WheelCollider wheelBR;
public float maxTorque = 50;
public float decelerationSpeed = 30;
public float currentSpeed = 0;
public float topSpeed = 600;
void Control ()
{
// Top speed & current speed
currentSpeed = 2 * 22 / 7 * wheelBL.radius * wheelBL.rpm * 60 / 100;
currentSpeed = Mathf.Round (currentSpeed);
if (currentSpeed <= topSpeed && currentSpeed > -maxReverseSpeed && !braked) {
wheelBR.motorTorque = maxTorque * Input.GetAxis ("Vertical");
wheelBL.motorTorque = maxTorque * Input.GetAxis ("Vertical");
} else {
wheelBR.motorTorque = 0;
wheelBL.motorTorque = 0;
}
}
Comment
Answer by EvilTak · Dec 14, 2014 at 04:27 PM
Probably check the velocity of the rigidbody, if its y component is < 0 it is going downhill?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Laggy Camera 2 Answers
object reference not set to an instance of an object Car.Carcontoller.CapSpeed() 0 Answers