Problems with wheels

Hello,

I tried to look up my problem in previous threads on wheel colliders, but unfortunately haven’t been able to find an answer. Sorry, if I missed it.
Anyway, it’s my first time playing with wheels and probably my issue is easy to fix.

I created a simple vehicle (box and 4 wheel colliders as child objects) and used a simple script, I found on a different thread:

private var hit : RaycastHit; 
var wheelBR : WheelCollider; 
var wheelBL : WheelCollider; 

private var buttonDown : boolean = false; 

function Update() { 
   var ray = Camera.main.ScreenPointToRay (Input.mousePosition); 

   if (Input.GetMouseButton (0)) { 
      if (collider.Raycast (ray, hit, 100)) { 
         buttonDown = true; // gas! 
      } 
   } 
    
   if (Input.GetMouseButtonUp (0)) { 
      buttonDown = false; // brake! 
   } 
} 

function FixedUpdate() { 
   if (buttonDown) { 
      wheelBR.motorTorque = -25; 
      wheelBL.motorTorque = -25; 
      wheelBR.brakeTorque = 0; 
      wheelBL.brakeTorque = 0; 
   } 
    
   else { 
      wheelBR.brakeTorque = 25; 
      wheelBL.brakeTorque = 25; 
      wheelBR.motorTorque = 0; 
      wheelBL.motorTorque = 0; 
   } 
}

If I click the car, it perfectly accelerates, but somehow starts to steer to the right as soon as it hits the ground (it’s slightly placed above ground).
I don’t have to do anything to make this happen. The longer I wait the more the rotation around y axis increases.

Does anyone know what is causing this?

Thanks in advance.

I had the same issue, but I solved it by freezing rotations on the rigidbody. Tho if you’re making a car that has steering too, then I guess you’d need to leave rotations enabled.

Anyway, I guess the question is: why doesn’t the vehicle track perfectly straight when the same force is being applied to both wheels? I’d like to know myself.

Well, at least I’m not alone…

Maybe it’s a general problem or there is something about car physics, that I don’t know or just haven’t understood yet.

Anyway, hopefully someone can shed some light on this.

Thanks in advance.

Old thread I know, but I’m having this issue as well. Does anybody know why cars want to pull to the right?

This might be the result of the centre of mass being miscalculated so it is not exactly in between the two wheel colliders. I don’t think there is any foolproof solution to this problem yet, but you could try shifting the centre of mass to the right very slightly to compensate.

Thanks for the reply. I’m trying this but the car then becomes unstable when turning, and I only need to turn slightly. It’s a drag racer of sorts so the speeds are very high.

I’m trying to understand some of the functions of the wheel colliders and haven’t figured them out.

I don’t know if this is applicable or not, but you might find it useful to add a configurable joint to the car to constrain its rotation while allowing it to drive.

Feel free to ask on the forum if you need any expansion on the docs.

Well my latest trick was to make the right wheel ever-so-slightly bigger in radius. It’s okay for now. Dragsters don’t shoot straight down the track without some steering being involved due to all the torque. I just couldn’t have it flying off to the right every time.

There seem to be a lot of issues with the wheel colliders and I may end up making my own system.

Now I’m trying to understand all the “slip” terms. Most of the problems in drag racing involve tire traction. Is there an explanation of how these values work that are easier to understand than the Unity docs provide?

Thanks for the reply btw!

Slip can be more easily understood if you think of the wheel as if it were more elongated, like a caterpillar track. If the car is rolling forward downhill, a given segment of track will stay positioned over the same spot on the ground until it gets lifted up at the back. In other words, the wheel/track is moving at the same speed as the road. When the wheel and road are moving at the same speed, no force (either drive or braking) is exerted. If the wheel moves slower than the road, the car will brake and if it moves faster, the car will accelerate (skidding and wheel spinning are the most visible examples of this). This difference in speed between the contact patch and the road is referred to as the the wheel’s slip.

A simple physical model might make the force exerted proportional to the slip, so the greater the speed difference, the greater the force. However, this is not how real tyres perform. They behave roughly like this until they approach a certain optimum slip value at which point the force tails off. After a certain point, any increase in slip makes almost no difference and the force remains the same. This is why ferociously spinning wheels, while looking spectacular, don’t pull away any faster.

This non-linear friction behaviour is modelled in Unity using the WheelFrictionCurve class. The “extremum” is the peak slip/force ratio, while the “asymptote” is the tail off value. The class lets you set the extremum in terms of the force value and the optimal slip value at which it occurs, and similarly for the asymptote. The “stiffness” parameter is a scaling value by which the extremum and asymptote forces are multiplied. This is set to 1 by default and is designed to allow the friction to be changed easily to simulate different road surfaces. So if you detected the wheel had suddenly hit a patch of oil, you would set the stiffness very low for a while.

The WheelCollider class actually uses two different friction curves for the forward direction of the wheel and the sideways direction. The sideways slip is the difference in sideways speed between the tyre and road (ie, any effect of wheel spin on sideways traction is not taken into account).

Thanks for the reply. I’ll try to wrap my brain around this :wink: