I have a car drive script, and when i try to turn the car (left or right) the car starts to flip i have wheelcolliders to each wheel (frontl, frontr, backr, backl) every wheelcolliders is a emptygameobject and all of those wheelcolliders inside other gameobject, then i have another emptygameobject called “Wheels” inside this emptygameobject
there are 4 more emptygameobjects and inside each of these 4 there is a wheel (model), this the code (the code is attached to the car):
var wheelFL : WheelCollider;
var wheelFR : WheelCollider;
var wheelBR : WheelCollider;
var wheelBL : WheelCollider;
var speed : float;
function Start(){
rigidbody.centerOfMass.y = 0;
}
function FixedUpdate(){
wheelBL.motorTorque = speed * Input.GetAxis("Vertical");
wheelBR.motorTorque = speed * Input.GetAxis("Vertical");
wheelBL.brakeTorque = 0;
wheelBR.brakeTorque = 0;
wheelFL.steerAngle = Input.GetAxis("Horizontal") * 10;
wheelFR.steerAngle = Input.GetAxis("Horizontal") * 10;
if(Input.GetKey(KeyCode.Space)){
wheelBL.brakeTorque = 20;
wheelBR.brakeTorque = 20;
}
}