Search Unity

Child objects with box colliders causing rigidbody to tip

Discussion in 'Physics' started by DroidifyDevs, Apr 25, 2018.

  1. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Hello,

    I made a simple model to test some scripts, yet I've run into a strange issue.

    Here's my situation:
    upload_2018-4-24_20-32-26.png
    As you can see, I have a rough character model and shotgun. ONLY the Character model has a rididbody; the shotgun has 3 box colliders. However, when the shotgun is enabled, it causes the character to tip over, even though the shotgun has no rigidbodies. I've come to the conclusion that the issue is the shotgun's box colliders, since when I disable the colliders, the character doesn't tip over.

    Why is Unity giving weight to my box colliders? How can I change this?

    Thank you!
     
  2. alfredronning

    alfredronning

    Joined:
    Jan 25, 2018
    Posts:
    4
    Maybe the caracter collides with the shotgun. If you just want the character from stop tipping you can lock rotation around z in the rigid body. You can also put the colliders on two different layers. In edit > project settings > physics you can set which layers collides with other layers.
     
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,512
    The issue is the center of mass. Unity computes the center of mass based on the colliders that belong to the rigidbody. As your shotgun is child of the character, it's assumed that its colliders belong to the character's rigidbody.

    Solution: explicitly assign Rigidbody.centerOfMass to the center of your character.
     
    DroidifyDevs likes this.