Unity's wheel collider need a "car" collider to function, otherwise it spins as soon as it touches the ground. Why is that?

Hello,

I’m new to game dev. I have made a simple car prototype which worked fine using wheel colliders. I then imported my first model I made using blender, than I deleted the cube I used to replace it with my model.

But, ô the infamy, ô the tragedy, the car started to spins as soon as it touched the ground. I couldn’t figure out why and I thought that the mesh renderer also had a collider component to it, and that the wheel was somehow colliding with it, creating this spin. But no : it spins because the Mesh I imported doesn’t have a collider.

I looked a few forums but no one had this particular issue (it’s a low brain power issue, I know), so I thought firslty that I would share it here in case someone have the same problem.

But I’m also curious, why does it act like this ?

Thank you for your imput =)
S.

Merely replacing the cube Mesh with your own won’t affect behaviour. So something else must be going on. Does the game object with the mesh (or one of its children) also have a Collider component? Or even a Rigidbody component?

“Spin” in what way? Do the wheels spin out and the car barely moves? That could indicate a simple increase in weight. If the entire car spins around, possibly wildly even doing airflips, then you likely have overlapping colliders or joints which cannot resolve their state, thus accumulating forces.

Is what you replaced merely the chassis on top of a working “frame with wheels” or is it a self-contained object, ie you also modeled the wheels and thus the object hierarchy changed?

Screenshots and, if possible, a video or gif would help.

Blockquote
Merely replacing the cube Mesh with your own won’t affect behaviour. So something else must be going on. Does the game object with the mesh (or one of its children) also have a Collider component? Or even a Rigidbody component?

I have one parent GameObject with a rigidbody, it’s responsible for the mass and the overall physics of the car.

The cube had a Collider component, Unity gives it one automatically when you use create > 3d Object > Cube. The Mesh I imported didn’t had one. I put a Collider on the mesh and it worked. I later decided to have the collider as a separate gameObject so that I can change the model without caring about that.

Blockquote
“Spin” in what way? Do the wheels spin out and the car barely moves?

The whole care violently rotates on itself like its inside a washing machine.

Blockquote
Is what you replaced merely the chassis on top of a working “frame with wheels” or is it a self-contained object, ie you also modeled the wheels and thus the object hierarchy changed?

yes, I replaced the cube gameObject with a car gameObject I imported from Blender. the hierarchy didn’t change, the only thing that changed was the boxCollider.

here’s how it’s organised :

So yeah, I just imported the mesh for the chassis and a mesh for the wheel (seen acting exactly the way I want them to in the attached picture =') )

Here’s a video cause it is pretty funny :slight_smile:

Nice. I can also tell you why that happens: Automatic Center of Mass. Pretty sure if you enable the “Automatic” checkbox again, it’ll work as expected. :wink:

I know because I did a simple car setup recently and wanted the car to stick more to the ground and thought moving the center of mass downward would help. Well, it did, but it’s non-intuitive and often resulted in this wild flip-over effect. The usable value range is pretty small (less than 1 for me) and highly dependent on the colliders eg the shape and size of the car.

You have this rather large BoxCollider, which means your car has a height of say 3-4 meters with a fairly wide distribution of mass and the “center of mass” probably somewhere close to but still above the ground.

Then when you tick off the collider, you have the same setup but for a sports car whose true center of mass is now below the floor. This - I assume - kicks off physics being like “oh no, it’s under the floor I better push it up” and since the center of mass is so far off-center now (far outside the actual physical body), this thing keeps toppling over.

Imagine this person:

:person_lifting_weights:

Except the weights would be 10m above the body, but the person would still (magically) hold those weights. And then imagine how difficult it would be to keep this balanced and what would happen to the person if it could not let go off the weight no matter what, and then the weight starts to fall to one side …

Long story short: always make sure the center of mass remains (well) within the overall bounds of all colliders of the object. Otherwise you have something that is physically impossible - a body’s center of mass can be very lobsided, but never outside the body itself.

The problem is clearly the inertia tensor of the Rigidbody, which the defines its moment of inertia. This is the rotational analog for mass.

By default, Unity calculates the inertia tensor out of the convex colliders associated to the Rigidbody. If there are no colliders, then the inertia tensor defaults to 1,1,1 (think of a rotational mass of 1 Kg in each axis). That’s the result of removing the box collider.

WheelColliders cause large off-center forces based exclusively on the downforce (mass). When the rotational inertia is 1, these forces produce huge angular velocities (similar to applying a large force to a small mass causing a huge linear velocity).

The solution is either using colliders resembling the shape of the vehicle, or disabling Rigidbody.automaticInertiaTensor and specifying an inertia tensor explicitly.