Getting car to brake automatically when input is released

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];



        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?

maybe this will do what you want:

if (Input.GetKeyUp (KeyCode.Brake))
// this
rigidbody.velocity -= new Vector3 (BrakeSpeed, 0, BrakeSpeed);
// if you don't have a rigidbody
Speed --;

try adding something like this to your car. is it what you want?

Instead of doing some fancy phisics thing to make the car stop, can’t you just set his velocity to test “if keyup” ?