Search Unity

[SOLVED] How to best use RBs, hierarchy, and multiple colliders in my project

Discussion in 'Physics' started by Palimon, Oct 8, 2015.

  1. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    I'm building a spaceship, and as I start layering in more rigidbodies and colliders inside that spaceship, I'm starting to hit on some strange interaction behaviors. Hoping someone much more knowledgable of Unity than I can point me in the proper direction for what I need! My game has a spaceship that players also move around inside while it's flying.

    Summary of hierarchy for my current spaceship:
    • Spaceship - RB which I use for physics flight
      • a bunch of floor colliders (kinematic RBs + trigger colliders)
      • systems (kinematic RBs + trigger colliders + scripts for subsystems to tell when they get damaged)
    Now, that's working fine, but what I'm running into is that I also want colliders on the ship itself for phsyics collisions. When I do that, they start interacting with interior colliders in strange ways and the ship often just starts spinning like mad. I believe I will suddenly have all my children colliders merge with my ship's to create a single compound collider. Is there a way I can have phsyics colliders on my ship that are completely seperate from any system/floor/etc trigger colliders? I could put all my spaceship physics on a child object of my spaceship, but then it's the child, not the spaceship itself which is moving which is very strange, and the other systems and such wouldn't follow it anyway. Ideas?
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    I wonder if those children kinematic RBs are really needed. What are they used for? Looks like the children RBs are interacting with the main RB, causing the issues.

    Without knowing the details of your project, I think that I'd use a single RB and then different layers of colliders and triggers. The OnTriggerEnter event is called per trigger collider, so you can learn exactly which collider has been hit.
     
  3. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Well, I suppose I could remove all the children and put every single collider on my ship with it's single RB, but even if that worked alright, I'd have hundreds of colliders on one game object - walls, floors, systems, control points, etc.
     
  4. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    So far I've been getting by without having any colliders on my ship object so that the colliders don't start compounding. But then I can't have the spaceship do phsyics collisions with external objects like asteroids and other spaceships.
     
  5. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    For anyone coming by later, after a bit of testing, looks like putting the different GameObjects in my ship's hierarchy into seperate layers (Floor, SpacePhysics, etc) and then changing up the physics layer grid in settings, the colliders no longer screw with each other. I can have my external physics impacts work with a RB collider on my spaceship, and the internal stuff work with kinematic RBs and trigger colliders. More testing required to see if everything I was doing previous still can work under this design.