- Home /
When I use WheelColliders, my car drifts to the left. Why?
I'm working with WheelColliders on a basic car model. As I decrease the side friction, my car begins to drift to the left (and only the left) badly. Why? Is there a way to fix this?
Here's the (extremely basic) script that controls my car at the moment:
var fr : WheelCollider; var fl : WheelCollider; var br : WheelCollider; var bl : WheelCollider;
var speed = 10.0; var steerSpeed = 10.0;
var COM : GameObject;
var gear = 4;
function Start() { rigidbody.centerOfMass = COM.transform.localPosition; rigidbody.angularDrag = 10; }
function Update() { if (Input.GetKeyDown ("1")) { gear = 1; }
if (Input.GetKeyDown ("2")) {
gear = 2;
}
if (Input.GetKeyDown ("3")) {
gear = 3;
}
if (Input.GetKeyDown ("4")) {
gear = 4;
}
}
function FixedUpdate () { fr.steerAngle = Input.GetAxis ("Horizontal") steerSpeed; fl.steerAngle = Input.GetAxis ("Horizontal") steerSpeed;
br.motorTorque = Input.GetAxis ("Vertical") * speed * gear;
bl.motorTorque = Input.GetAxis ("Vertical") * speed * gear;
}
Answer by Edy · Nov 30, 2010 at 12:42 AM
Ensure that the center of mass (CoM) is properly set to the exact center of the WheelCollider's positions. If the CoM is slightly biased to a side, the WheelColliders of that side will support more weight, which means higher friction forces at that side.
As far as I've experienced with WheelColliders there's no such bug (See my Live Demo on vehicle physics with WheelColliders). There was a similar misbehavior in Unity 2.x, but it was fixed in Unity 3.
Okay, thanks. I haven't tested but it seems reasonable so I'll accept.
Answer by bitbutter · Jan 29, 2014 at 03:58 PM
The reason for the drifting seems to be some kind of bug related to fixed timestep. The drifting can be removed by reducing the timestep, see animated gif below for a before and after.
Answer by elbon96 · Oct 29, 2010 at 12:47 PM
In the end, I decided to use a rather hacky fix that solved the problem, which, after further research, I learned was a bug with the standard WheelCollider. I added a value to the steerAngle on top of my turning values, like this:
fr.steerAngle = Input.GetAxis ("Horizontal") * steerSpeed + counterDrift;
fl.steerAngle = Input.GetAxis ("Horizontal") * steerSpeed + counterDrift;
It works, but if anyone has a better solution, I'd be glad to hear it.
I'm having the same issue. I've checked and double checked that everything is symmetric. Did you ever solve this?
Your answer
![](https://koobas.hobune.stream/wayback/20220613081227im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why does my car re-align after drift into the original direction? 0 Answers
Unity Car Controller Collision Reverse 1 Answer
How can I allow WheelColliders to free-roll? 0 Answers
How do I get my wheel mesh to rotate on the proper axis? 3 Answers
How can I get current lateral and longitudial friction forces from standart WheelColliders? 0 Answers