Very Simple Car Questions

So in the game I’m making, you essentially have to drive a little truck to the pickup station, get the item that needs the delivery, then take it to the destination. I’m working on just the first level which is a straight run with no obstacles so I’m purely working on the car physics right now. I’ve got a simple car going, but it flips so incredibly easy it’s pathetic and the car is hardly moving at all. The car is never supposed to catch any air so is there any way to constrain it to the ground? It’s going to be top down so the Y-axis isn’t even a factor in the game.

I lightened it up so it’s more visible what’s actually going on. Here’s the Mac and PC stand alones, not sure how to put it as a playable game online…

That never even crossed my mind… Thanks:) Will that solve the rolling do you think?

One last question, now that I’ve got that all sorted out, thank you:), I’m not sure how to make a brake system. Simply pressing reverse takes forever to slow it down. I figure I have to alter the velocity in some way but have no idea how…

Here’s my code:

``````var FLWheel : WheelCollider;
var FRWheel : WheelCollider;
var maxForwardSpeed : float= 50.0;
var maxReverseSpeed : float= 50.0;
var EngineTorque : float = 25;

function Start () {
rigidbody.centerOfMass += Vector3(0, -.5, 0);
}

function Update () {

/*Apply forward motion (Torque) to the front wheels*/
FLWheel.motorTorque = -EngineTorque * 10 * Input.GetAxis("Vertical");
FRWheel.motorTorque = -EngineTorque * 10 * Input.GetAxis("Vertical");

/*This limits the car to a max speed. It is negative because the input for up and down
are reversed for whatever reason*/

if(FLWheel.motorTorque && FRWheel.motorTorque < maxForwardSpeed){

FLWheel.motorTorque = -maxForwardSpeed;
FRWheel.motorTorque = -maxForwardSpeed;

}

/*This limits the car to a max speed when travelling in reverse. Horizontal input is correct,
so no negatives need to be put in place.*/
if(FLWheel.motorTorque && FRWheel.motorTorque > maxReverseSpeed){

FLWheel.motorTorque = maxReverseSpeed;
FRWheel.motorTorque = maxReverseSpeed;

}

/*Turn Radius variable increases or decreases the tightness of the turn*/

rigidbody.constraints = RigidbodyConstraints.FreezeRotationX;
rigidbody.constraints = RigidbodyConstraints.FreezePositionY;
``````

}

I haven't made a car in unity yet, but from what I read in the docs you should use Brake Torque for braking. Something like this maybe->

``````var brakeButton : String = "MyInputBrakeButtonName" ;
var brakePower : float = 100.0 ;

//in update() with your other stuff->
if(Input.GetButton(brakeButton)){
FLWheel.brakeTorque = brakePower ;
FRWheel.brakeTorque = brakePower ;
}

``````

Note: you're only going to have front brakes like that lol