Hi there. I have some problems using wheel colliders. I got a car mesh and wheel meshes. There is an empty object with every wheel which holds the collider. There is also a script attached to the collider.
var acceleration : float = 100;
function FixedUpdate()
{
force = Input.GetAxis("Vertical") * acceleration;
collider.motorTorque = force;
}
The wheels are in perfect symmetrical position around the car. The car.centreOfMass is at 0,0,0. The surface is a flat plane in default position. When I press throttle button, the car starts to move but steers to the right.
To sum it up, everything is in its default setting yet turns for no reason. If I add the script to all 4 colliders (currently its FWD), the steering is a bit smaller but it still steers to the right. One more thing, the steering happens only when I add force. If I release the throttle button the car goes straight. It just acts as if my right wheel is blocked.
Any ideas? I can try tweaking the centers of colliders, but that doesn’t seem right.
Any help is appreciated.
P.S. I haven’t used collider.steerAngle yet so I know this is not the issue.
function Start () {
wheels = (GetComponentsInChildren(WheelCollider));
}
for (var wheel : WheelCollider in wheels) {
force = Input.GetAxis("Vertical") * acceleration;
wheel.motorTorque = force;
}
At least, that’s my assumption. This will be the case if this script is attached to the car itself, and not each wheel.
Edit: Although that was my initial though, I can’t tell exactly what you’re doing with the script from what you said (“If I add the script to all 4 colliders”)…I assume by this, you mean the GameObject that has a wheel collider attached. If so, then what I said won’t help, of course.
The only other things I can think of is that your modeled object is not symmetrical, in terms of colliders, or that one or some of your wheel colliders are rotated slightly. Forward friction on the wheel colliders should be identical as wheel, for wheels that are parallel along the length of the car.
yes, what i meant was that a script is attached to EACH of the gameObjects holding a collider (only the front wheels, because I want a FWD car). As I said, attaching the script to the rear wheels (making it 4WD) only lowered the steer, but hasn’t removed it completely.
The mesh is completely symmetrical (all meshes were built in unity, no external geometry). I first built one wheel, then duplicated it and placed it around the car. So, I’m absolutely positive that they are in perfect position.
I repeated the process several times, only to get the same effect
Don’t know where the problem is. I reported a bug, we shall see.
Edit: Later I found out that setting
rigidbody.centerOfMass = Vector3 (0, -0.625, 0);
fixes the problem to some point (not really a fully legit fix) but at least I can focus on other stuff now.