Has anyone successfully set rigidbody.inertiaTensor manually? I just tried it and found that it gives weird and undesirable results, even if I don’t change its component values, i.e. rigidbody.inertiaTensor = rigidbody.inertiaTensor.
My use case is: I have a hover vehicle, and I want to adjust how much it rolls (rotates around the z axis) when it turns a corner.
If I’m not missing something obvious I will try to create a simple example to demonstrate the problem. Thanks!
Setting it to its current value instructs the inertia tensor not to update its value automatically based on the Rigidbody properties (mass, colliders). So for example, if you have that code in an Awake() method, most likely the value of the inertia tensor will be 1,1,1 and it won’t be updating itself. If you put that code in Start(), then the inertia tensor has already initialized with the properties of the RB and will preserve them on future changes.
Check out the documentation of the inertia tensor for more details:
Thanks for your reply. I’ve figured out what’s going on now.
TLDR: I am also setting the Rigidbody’s mass programmatically, and I should have been calling ResetInertiaTensor() afterwards.
Details:
I set the Rigidbody’s mass programmatically according to a value loaded from file.
Initially the mass is a sensible value e.g. 50
I was erroneously setting the mass to a value of 0 temporarily
After this code the Rigidbody’s mass was actually 1e-07, not zero. I don’t know why. Maybe a value of 0 is forbidden and it’s handled in Rigidbody.mass’s property setter.
This led to the inertiaTensor automatically changing so that its values were very small
Then I was setting the mass to a sensible value again e.g. 60
This did not lead to the inertiaTensor changing. I’m not sure why, given that it changed in step 5.
For months this has been the setup and there were no negative consequences. My physics objects behaved as expected. I thought that setting the mass to 0 temporarily was innocuous. But when I added the line to set the inertiaTensor manually, it led to the undesired behaviour (jittery movement).
By calling ResetInertiaTensor() immediately after setting the mass, the problem was fixed. The inertiaTensor had sensible large values again and the undesired behaviour was gone.