I have a RigidBody, not a fancy one, very simple. I must set manually the center of mass to this RigidBody. Doing so it looks like I trigger two bugs in Unity:
first one: as far as I understood, once I set the center of mass manually, Unity should stop recompute it if I change the RigidBody colliders, this instead does not happen, Unity changes the center of mass, forcing me to recompute it again.
second one: after I set new colliders in the rigidbody, the inertiaTensor and inertiaTensorRotation go completely mental. I am forced to remember the old values to still have a good simulation.
Example:
Vector3 inertia = rbTransform.rigidbody.inertiaTensor;
Quaternion rotation = rbTransform.rigidbody.inertiaTensorRotation;
//inertiaTensor here is 17.8, 16.4, 4.8
for (int i = 0; i < colliderCount; ++i)
{ //allColliders contains gameObjects with only one BoxCollider component
Transform collider = allColliders[i];
if (collider.parent != rbTransform)
collider.parent = rbTransform;
collider.localRotation = Quaternion.identity;
collider.localPosition = collider.position;
collider.gameObject.SetActive(true); //set active must stay after the parenting!
}
//new inertiaTensor is now: 11491.2, 11492.6, 2.7
rbTransform.rigidbody.inertiaTensor = inertia; //I am forced to do this
rbTransform.rigidbody.inertiaTensorRotation = rotation; // and this
any clue?