I’m running into a very strange problem… which I think may answer some questions others have been having with wheel colliders. (I remember there was a guy who had a drifting vehicle at rest – I think this problem is related…)
I’m building a tracked chassis with five wheel colliders per side. Starting point was the VehiclesExample tank, but I’ve since modified it beyond recognition.
At any rate, something I noticed out of the box was a tendency for the vehicle to drift to the left. After further tweaking, and messing around, I finally hit upon what is causing the drift. The springs on the wheels are not equal!
Apparently, looping through all the wheel colliders and setting the spring rates actually keeps setting them to higher and higher values – as if the value I’m setting it to is incrementing! The result is a serious list. Changing the order of the looping changes the way it leans. This is very apparent with low initial spring rates.
I think this is a bug.
var springForce :float = 20;
var damperForce :float = 50;
private var leftRight;
var leftTrack : TrackSection[];
var rightTrack : TrackSection[];
class TrackSection
{
var bone : Transform;
var graphic : Transform;
var position : Vector3;
var maxTravel : float;
var colObj : GameObject;
var col: WheelCollider;
}
function Awake(){
leftRight = new Array(leftTrack, rightTrack);
for(i=0; i<2; i++)
{
var j = 0;
for(var b : TrackSection in leftRight[i])
{
b.position = b.bone.transform.localPosition;
b.colObj = new GameObject("WheelCollider" + i + j++);
b.colObj.transform.parent = b.graphic.parent;
b.colObj.transform.rotation = Quaternion.identity;
b.colObj.transform.localPosition = b.position;
b.colObj.transform.parent = transform;
b.col = b.colObj.AddComponent(WheelCollider);
b.col.suspensionDistance = suspensionDistance;
b.col.suspensionSpring.spring = springForce;
b.col.suspensionSpring.damper = damperForce;
//no grip, as we simulate handling ourselves
b.col.forwardFriction.stiffness = 0;
b.col.sidewaysFriction.stiffness = 0;
b.col.radius = wheelRadius;
}
}
}