Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Resolved Is nesting rigidbodies still not recommended?

Discussion in 'Physics' started by BrownBrew, Mar 22, 2023.

  1. BrownBrew

    BrownBrew

    Joined:
    Jan 6, 2023
    Posts:
    13
    Hello!

    I found some old info that nesting rigidbodies isn't recommended since it can cause weird physics behaviour. Is this still valid?
    In my case I use separate rigidbodies for the player and it's hitbox (player is for physics and other interactions and hitbox exclusively for enemy projectiles). Player is set to Dynamic, hitbox is Kinematic.
    2_1.jpg
    Can it cause issues or am I fine?
     
  2. BrownBrew

    BrownBrew

    Joined:
    Jan 6, 2023
    Posts:
    13
    I'd really appreciate if anyone could give me an answer before I implement this for every single enemy in the game only to rework everything later. I can see how nesting dynamic rigidbodies might be an issue, but what about kinematic ones?
     
  3. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,533
    Use one rigidbody. In your case, have the hit-detector code on the Player, since hits from all colliders percolate up to the object with the rigidbody. If you really really want the hit-processing code on the hitbox, have the Player object "forward" the hits to it.
     
    BrownBrew likes this.
  4. BrownBrew

    BrownBrew

    Joined:
    Jan 6, 2023
    Posts:
    13
    Thanks a lot for the reply! :)
    I was concerned that it would be difficult to tell which collider hits which in case I have many of them (like triggers, hitboxes and stuff), but I actually only now realized that a child object still can have a separate layer and tag. That means in OnTriggerEnter2D if I compare the collider's tag and it's "Hitbox" - that means there's nothing else but the enemy's damagebox hit it (if the collision matrix is set correctly).
    Thanks once again!