Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rigidbody2D and non-trigger child colliders!

Discussion in 'Physics' started by Aedous, Oct 30, 2015.

  1. Aedous

    Aedous

    Joined:
    Jun 20, 2009
    Posts:
    244
    Hello!

    I have a simple question with colliders and rigidbodies just for 2D. I have a character gameobject with a Rigidbody2D attached to it with a circle collider, this also has a child gameobject with an extra collider in the child which is not a trigger. Now considering that the character is always going to be moving around, must I have a Rigidbody2D also attached to the child colliders?

    The reason I'm asking is because I've read around on the interwebs that if a "solid" collider does not have a Rigidbody attached to it Unity assumes this collider is static and does not move and therefore saves on performance. So does the fact that the parent collider has a Rigidbody automatically let Unity know that these other solid child colliders will also be moving around?

    Any help will be really appreciated :D.
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    823
    It doesn't need a second rigidbody, unless it is moving in the parent object itself and should as well have physics calculations (For example a space ship with a human in it, that runs around and does stuff).

    I like to encapsulate the colliders themselves in child objects for a cleaner structure. That especially helps, if you want to use more than one basic collider to approximate the shape of the gameobject. So in my case the more complex objects often look like this:

    Player
    - Colliders
    -- Head
    -- Body
    -- LeftArm
    -- RightArm

    (Player has the rigidbody)
     
  3. Aedous

    Aedous

    Joined:
    Jun 20, 2009
    Posts:
    244
    Thanks for clearing that up! :D