I have a car being controlled by wheel colliders and an engine script that I want to stop immediately when the input key is released and not move again until the input is pressed (not realistic car behavior but this is for gameplay purposes, it’s not a racer or simulation). Except using my brakeTorque script causes the car to not move at all:
void Update () {
EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm)/2 * GearRatio[CurrentGear];
ShiftGears();
audio.pitch = Mathf.Abs(EngineRPM / MaxEngineRPM) + 1.0f;
if(audio.pitch > 2.0f) {
audio.pitch = 2.0f;
}
FrontLeftWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis ("Vertical");
FrontRightWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis ("Vertical");
FrontLeftWheel.steerAngle = 10 * Input.GetAxis ("Horizontal");
FrontRightWheel.steerAngle = 10 * Input.GetAxis ("Horizontal");
if(Input.GetAxis ("Vertical") == 0){
FrontLeftWheel.brakeTorque = Mathf.Infinity;
FrontRightWheel.brakeTorque = Mathf.Infinity;
}
Am I using Mathf.Infinity wrong here? I figured applying infinite brakeTorque would keep the car still until the input is pressed again. Or is there something else wrong with the script?