Unity Car tutorial Brake

Hi,

I am using the car and some scripts from the Unity3d car tutorial, and when I accelerate then release the button, the car keeps on going, and even after I brake it, it rolls. How can I set it to decelerate faster,and to stay stopped?

Ok, so its pretty complex as expected. Found the line where the braking takes place. Line 527 of the car script(java).

rigidbody.AddForce(transform.forward * Time.deltaTime * (throttleForce + brakeForce));

Here are the 2 vars that handle the acc/dec of the car.

NOTE: If you are using this script w/o changes, acc/dec will be at the same rate(the posted line handles both acc/dec). So if you are trying to stop quicker than you accelerate, it might be a good idea to make an add on script that applies additional stopping force.

Theres a few ways to add extra brake force. You could add a boolean to the car script called braking and make this true when the throttle force is negative.

public var braking:boolean;

function Update()
{
    if(throttleForce<0)braking=true;
    else braking=false;
}

then from the new script

public var braking:boolean;
public var extraBrakeForce:int;

function FixedUpdate()
{
    braking=transform.GetComponent(Car).braking;
    if(braking)rigidbody.AddForce(transform.forward*Time.deltaTime*(-extraBrakeForce));
}

Not tested, but should work. Dont forget to set your extra brake force from inspector. Let me know if it works out ok.