Search Unity

Building made of many rigidbodies

Discussion in 'Physics' started by Ryukai3, Jun 4, 2017.

  1. Ryukai3

    Ryukai3

    Joined:
    Mar 30, 2017
    Posts:
    30
    Hi,

    I'm tryng to make a building made of various rigidbody:
    The objective is that my building may be destructed one piece at a time.

    These are the setups that I have tryed at the moment:

    Setup1:
    There is a "Wall" gameobject parent of various "WallFragment" gameobjects.

    • The "Wall" have a rigidbody with gravity and a mesh collider "is trigger" (mesh with convex because is not a cube but a trapezoid). This gameobject doesn't have a mesh renderer.
    • The "WallFragment" have mesh renderer, no rigidbody, and a mesh collider convex. There are 8 WallFragment inside each Wall. MaxFriction material (this is for stability issue).
    Wall and WallFragment both have MaxFriction material. (this is for stability issue).

    There are other gameobjecst in the game that, in some occasion, will destroy the WallFragment of certain Wall.

    My building is composed of nearly 21 Wall (and thus 147 WallFragment), with some levels (Wall stacked above of other Wall).

    All is perfect with this setup (the building behave in the way it should)...despite that with Android the frame rate drop to 20-30 fps...I think that the problem is (profiler wise) ALL the rigidbody are constantly active, never sleep. Some stats of every frame:

    Active Dynamics: 25
    Active Kinematics: 0
    Statis Colliders: 5
    Rigidbody: 27
    Trigger Overlaps: 2
    Active Constraints: 644
    Contacts: 1.4k



    Setup2:
    • The "Wall" have a rigidbody with NO gravity and NO kinetmatic and a mesh collider "is trigger" (mesh with convex because is not a cube but a trapezoid). This gameobject doesn't have a mesh renderer.
    • The "WallFragment" have mesh renderer, rigidbody with gravity, fixed joint connected with the parent Wall rigidbody, and a mesh collider convex. There are 8 WallFragment inside each Wall.
    With setup2, this is the physic profiler stats:

    Active Dynamics: 4
    Active Kinematics: 0
    Statis Colliders: 5
    Rigidbody: 193
    Trigger Overlaps: 17
    Active Constraints: 48
    Contacts: 35

    So...less CPU stress, all sleeping here, 60 fps, until...another rigidbody impact with the building...(the player or another gambeboject with rigidbody), in that case ALL the building AWAKE and the fps drop again at 10...


    For your information i have these options in physics:
    Enable Adaptive Force ON
    Sleep Threshold: 0,05

    So...what I'm doing wrong? There is some better performance method to make a destructable building?

    My game is 3d and the target application is Android.

    Here a screnshot:
    exampleWall.png exampleWall.png


    Thank you all in advance guys :)
     
    Last edited: Jun 4, 2017
  2. mtytel

    mtytel

    Joined:
    Feb 28, 2014
    Posts:
    84
    eXonius likes this.
  3. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    650
    Are you still working on it? How is it going? There are few building destruction games out there, everyone of them seems to use physic constrains (even Red Faction Guerilla does)
     
  4. Ryukai3

    Ryukai3

    Joined:
    Mar 30, 2017
    Posts:
    30
    Hi! Thanks for the interest!
    Yes, Im still on it and, after a lot of testing, Im now using a script that simulate physic that work mainly with oncollision or trigger events.
    I also have changed some settings of rigidbodies and child and now the performance satisfy me, even the behaviour.

    At the moment withtthis System I have experienced this problem : https://forum.unity.com/threads/iskinematic-false-strange-penetration-behaviour.605530/#post-4059235
     
  5. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    650
    Cool, I am working on something similar too, I am trying out the 7th approach already, maybe we could have a short chat on that topic on any chat-platform (facebook, WhatsApp,...)?

    I'd also be very interested in a Video of your system, heres one of the 7 attempts (with some physic calculations and dust particles deactivated), WIP: