Hello, I have a frequent but unpredictable issue where rigidbodies start with Inertia even though I haven’t set anything to do with it. It’s causing me no end of problems because deleting and remaking the rigidbody does nothing. I have to restart if I see this, and that doesn’t always make it go away. Any ideas why? This image was not taken in playmode!!
Correct me if I’m wrong, but I always thought Unity automatically calculates the inertia of the rigidbody based on the game object’s colliders and mesh if you did not manually set it in script. If you really do not want any inertia at all, just check freeze rotation for all the axes.
I wouldn’t say this is a bug unless I’m reading your post wrong.
That
That is correct. By default Unity calculates the center of mass and the inertia tensor of the rigidbody automatically based on the colliders associated to that rigidbody (in the same GameObject or in children GameObjects). This means that if you modify the colliders (adding, removing, moving) then both the center of mass and the inertia will be recalculated and the rigidbody will react differently to forces and torques.
If you want the same and predictable behavior in your rigidody no matter the colliders associated you can do so like this:
- Configure a rigidbody you’re happy with.
- Read the values of inertia tensor, inertia tensor rotation and local center of mass.
- In the initialization section of your script configure Rigidbody.inertiaTensor, inertiaTensorRotation and centerOfMass to these values.
Then the behavior of the rigidbody will be the same no matter the configuration of its colliders, or if it has colliders at all.
It’s not doing this for the other five identical objects I have sitting in a line, so something is up.
Quite often I will drag an object into the editor window, hit play, and the forces that are applied to it automatically will get yeeted into space if there’s no gravity.
I mean, I’m not doing anything special with this object. I dragged a mesh into the editor window and added a rigidbody.
That’s makes Unity calculate the inertia based on the convex colliders associated to the rigidbody. If there are no associated convex colliders then it will calculate a default inertia, the identity, which in most cases that’s what you don’t want. Rigidbodies with identity inertia are highly unstable because likely any force not applied at the center of mass, or any applied torque, will cause them to rotate out of control at high rates. I haven’t tested, but possibly this includes contacts and collisions.
So don’t drag it into the window and add a rigidbody?
Think of the inertia tensor as “mass for rotations”: you never want the inertia tensor to be zero! By the way this has nothing to do with the object having some inertia, or cause the object to start moving by itself if that’s what you were thinking.
Unity will automatically calculate the correct inertia tensor value for you with is extremely nice. Thank you Unity, sir!
If you want the object to not be affected by forces/gravity, make it kinematic.
Then after you instantiate it, disable the kinematic checkbox if you want it to be affected by forces/accelerations again.
If your non-kinematic rigidbody starts moving right away when you press play even in absence of gravity, check whether it starts out intersecting some other object: that will push it outside the other object very fast and yeet it into oblivion.
Ah okay thanks