AddTorque() not behaving as expected, but directly adding to rb.angularVelocity imparts velocity

I think it has something to do with the center of mass of the rigidbody because it is a really big and weirdly shaped spaceship, but when I add torque to it say around the up axis it will also twist on its forward axis a little, causing it to rotate on a completely different axis.

The only way I have figured out how to stop the unwanted rotation is by manually adding to rb.angularVelocity instead of using AddTorque(). Doing it that way it now spins on the axis as expected, but there is another problem now, when I add to rb.angularVelocity, it imparts velocity on the spaceship. Meaning if I am completely still and rotate the nose down for instance, when I stop rotating, the whole ship will be moving downward.

So I need help either figuring out how to get AddTorque to only add torque on the axis I specified, or stop rb.angularVelocity from imparting velocity. Thanks.

I turned on “Interpolate” on the rigidbody and that actually stopped the angularVelocity from imparting velocity.

Nope, that’s not true. Interpolation is an artifact of the Transform, it makes no difference to the physics simulation itself. Interpolation moves the transform from the old Rigidbody position to the current Rigidbody position; the Rigidbody isn’t affected.

If you’re reading the Transform position/rotation and using those results to modify the physics then it’ll make a difference but that’s your script being incorrect. This is why you should always read the Rigidbody state, not the Transform state.

Btw, it’s always worth mentioning 2D or 3D physics here because it’s not always obvious.

1 Like

That’s because of the rotation of the inertia tensor. By default, the inertia tensor of the rigidbody is automatically calculated out of the colliders attached to the rigidbody. When these colliders are not symmetrical around the center of mass, that results in a non-uniform inertia tensor that is stored in the rigidbody as a rotation of the inertia tensor.

Quick fix: set rigidbody.InertiaTensorRotation = Quaternion.identity and AddTorque will work as you expect.

2 Likes

Bro thank you so much.