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. Dismiss Notice

[RELEASED] Destructible Buildings

Discussion in 'Assets and Asset Store' started by bobadi, Feb 11, 2021.

  1. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
  2. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    was able to get chunks combined
    (if you bought the package and want to get before the update hits the assetstore, get in touch)

    combine1.gif combine2.gif

    combined objects (non-rigidbodies) and uncombined (rigidbodies)
    combinedNnot.gif
     
  3. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    new pieces coming to the upgrade
    nuobjs.jpg

    also some prefab fixes
    and project version 2019.4 (instead of 2020.1)
     
    Last edited: Feb 26, 2021
  4. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    significant performance can be gained if glass/windowframes/doors chunks are turned off

    destructnowindowsrb2.gif
     
    Last edited: Mar 1, 2021
  5. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    new script that can swap pieces to create variations
    new building
    build6.gif
     
  6. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    new version (1.3) has been uploaded
    it now includes structural collapse
    structcollapsex.gif



    dbuilds1006.gif
    UNITY VERSION: 2020.3.19
     
    wetcircuit likes this.
  7. vertexx

    vertexx

    Joined:
    Mar 18, 2014
    Posts:
    347
    Hi. This latest version.Does it work with 2019LTS? Does the destruction occur with collisions from any type of rigid body/collider? Does your asset require any scripting at all or can it all be done simply via "ticking boxes and changing values"? Thanks!
     
  8. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    Hi. it works in every version of Unity since 5.6, but will have to use 5.6 scene files, which I'll upload to my webpage and will link here.

    the destruction is scripted, which means on collision (and everlapbox on explosion) the affected colliders are collected and those elements of the building are turned into non-kinematic prefactured rigidbodies.
    there's one script for collecting chunks (into folders) with mesh-combine
    and one script for structural collapse for each building.

    the explosion/collision script
    sc1.jpg
    the chunk-collector script
    sc2.jpg
    the building structure script
    this has to be run twice to set up / analyze building data
    sc3.jpg
     
    Willbkool_FPCS likes this.
  9. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    almost forgot

    here are the 5.6 scene files
    https://www.mediafire.com/file/wrzvibjjalwzd27/_demo.zip/file

    noticed the scene file size is too big, don't know what caused it
    but you can see how to set up the buildings and destruction
    update:
    didn't find anything. looks like many object parts add to the scene file size
    (even if they are not active) though one say they do other say they don't

    now that I think about it, the prefabs probably won't work in a previous version
    so I think I should upload it with 2019.4
     
    Last edited: Oct 16, 2021
  10. Delycan

    Delycan

    Joined:
    Mar 2, 2022
    Posts:
    2


    So if I use these 3 scripts, the destruction will work?
     
  11. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    dbuildscollapse.unity
    destructbuildcs.gif

    future>>
    these should be combined after collapse
    need another one like combine-sequencer
    combinethese.jpg
     
  12. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    yes. you need those three script for destruct dbuild prefab, for collapseable building setup, and mesh combiner for chunks
     
  13. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    I think I improved the mesh-combine management

    in the scene view you can see the contents of the chunksFolder
    : the chunks go here and are combined

    recorded at 2 fps
    dbuildcomb2.gif

    also now buildings can be combined (createCBuild.cs)
    dbuildcreateC.gif
    this might be used to have less objects in scene and instantiate the
    modular destructible building only when destruction is imminent
     
    Last edited: Apr 28, 2022
  14. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    ran into an issue of chunks staying in air, if there is a collapse after the chunks got combined
    combineissue.gif

    this used the condition of chunks rigidbody velocity value (ie. they are not moving)
    and not using the condition of height (ie.the chunks are near the ground)

    so there's a new script introduced (getFracReComb.cs)
    which should check the height of combines chunks (those are being kept switched off, so
    there is a possibility to turn them back into rigidbodies again)

    a tip:
    if you don't want to have too big section collapse, keep the section-defining colliders 1-2 pieces wide.

    tip2:
    if using rigidbody for collision and destruction, collision detection should be continuous

    performance test
    combineperfotest.gif
     
    Last edited: Jun 14, 2022
  15. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    how to set up collapse (buildStructx.cs)
     
  16. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
  17. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    there seems to be a mistake in latest version
    in getFracPieces in update
    if (destructed && Time.time > checkF) {
    should be
    if (destructed && Time.time - dstartT > checkF) {

    but in new version I already changed those times to lists
    because if destruction happens, times get pushed back and
    combining doesn't happen while that time isn't reached

    also now (selectable) when destruction happens, all chunks are being identified in the buildStruct lists
    and marked as .off

    so simulation should be more precise
    note: frequency of combining can be set in (seconds) getFracPieces.checkD and getFracPieces.checkC
    getFracPieces.checkD : time after destruction / explosion
    getFracPieces.checkC : time after collapse

    the new version of previous performance test
    combineperfotest2.gif
     
  18. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    added changing materials [ demo / switchMats ]
    switchmats.jpg
    switchmats2.jpg
    which are changed on fractured pieces too
    switchmats2b.jpg


    update:
    I'll have to work a bit more on the update

    what I found:
    - frac objects must be set to frac layer if you want the collapse to work properly
    was introduced in 1.4 and there's changeToLayer.cs included

    - in case when a block is not damaged but every block around is destructed, it remains kinematic

    so new class was introduced buildStructx.sections.blocks
    this finds block pieces around every block (above, below, left, right)
    [this can fail, since there can be 2+ pieces above or below, but the drawback should be
    that it falls, even if it maybe should not)

    but automatic setup does not work for irregular shapes, only for flat and pieces like this
    blocks.jpg
    in inspector
    blocks1.jpg

    what I did :
    - tried out if using overlapbox for single chunks that get removed from combined mesh works
    it fails if there's more pieces are together
    the code is in [but shouldn't use this]:
    Meshcombiner.removeChunks0()
    bool getFracReComb.removeIfOBoxZero.


    - found a bug. if a floor piece is fully destructed the whole section crumbles
    (this should only happen if it is a wall piece)
    solved> piece type is determined by master floor folder in buildStructx.cs

    now no piece should be left hanging in air
    but it doesn't happen instantly, just when time is scheduled (for raycast checks)


    what could be done :
    - chunks positions could be tracked on every getFracReComb (and only those chunks would be removed from combined mesh that changed height from the last combine)

    - for a block could have a percentage of destruction (that would affect if above block should collapse etc)

    - there is a possibility to leave the windows chunks out from list
     
    Last edited: Jun 16, 2022
  19. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    new pieces that are coming

    nupieces.jpg
     
    paulojsam and SamKennedy like this.
  20. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    591
    new update coming

    - can select overlapbox to check piece below chunk (not just raycast)
    - can randomize next recombine time [geFracPieces.reComb.random min-max]

    - now pieces below chunks are checked before recombining
    getFracPieces.removeFreeChunks()
    OLD
    destrOld.gif
    NEW
    destrNew.gif

    also there is a carhit demo now
    destrCarHit.gif