Rigidbody with multiple colliders

I’m using a gameobject with a rigidbody and multiple box- and capsule colliders attached to it. When I start the game the position of the gameobject changes a bit (even when I freeze the position of the rigidbody).

When I rotate the object using rigidbody.AddTorque it’s rotation changes in all directions even though I’m only adding torque in 1 direction and freezing the rotation of the rigidbody in the other directions.

The problem doesn’t occur when I’m using only 1 collider on the gameobject. I’ve tried adding the colliders to childobjects of the main object but that doesn’t help. I could reset the position and rotation of the gameobject in LateUpdate() but would be an ugly workaround. The problem also occurs when I’m using a single mesh collider instead of multiple primitive colliders.

What could go wrong? Thanks in advance.

Found the problem. For people wondering what is was: adding colliders changes the center of mass and rotation behaviour of a rigidbody. To set those manualy to the center of the object use:

    void Start()
    {
        rigidbody = GetComponent<Rigidbody>();
        rigidbody.centerOfMass = Vector3.zero;
        rigidbody.inertiaTensorRotation = new Quaternion(0, 0, 0, 1);
    }
5 Likes

Thank you very helpfull!