#pragma strict
var WheelRL : WheelCollider;
var WheelRR : WheelCollider;
var WheelFL : WheelCollider;
var WheelFr : WheelCollider;
var MaxTourque : float = 50;
function Start () {
rigidbody.centerOfMass.y = -0.9;
}
function FixedUpdate () {
WheelRR.motorTorque = MaxTourque * Input.GetAxis("Vertical");
WheelRL.motorTorque = MaxTourque * Input.GetAxis("Vertical");
WheelFL.steerAngle = 5 * Input.GetAxis("Horizontal");
WheelFr.steerAngle = 5 * Input.GetAxis("Horizontal");
}
That’s the car movement script, but my car vears off to either left or right direction when I go forward…
As far as I can see you code is pretty much correct. So you might need to seek the error in the Wheel Collider settings.
Just some ideas what could cause the problem.
Do all Wheels have the same friction settings?
Is the center of mass in the center the car (except the y position)?
When creating vehicles in Unity, if you leave all of the default settings of the Wheel Collider then it usually does drive off to the left/right. What I’ve found is that the Spring needs to be set much higher to probably 10 or so. The Suspension and Damper can usualy stay the same but just play with it if it still doesn’t work.
Also if it still is giving you problems, try changing the Stiffness Factor for both Forward and Sideways Friction to something lower such as 0.1.