Search Unity

Dynamic 2D Destruction!!!

Discussion in 'Works In Progress - Archive' started by TheValar, Mar 18, 2014.

  1. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I've been wanting to do something with 2d destruction for a while and I finally got motivated enough to start working on something.

    WEBPLAYER

    So far this system is capable of shattering 2d sprites into triangle fragments at runtime.

    NOTE: I am NOT just breaking a pre-existing mesh into triangles.

    What's happening under the hood?
    This system can destroy any Unity Sprite with a PolygonCollider2D, Rigidbody 2D, and Explodable Component.
    The script takes the points of the collider and uses them to triangulate a new mesh which is uv mapped to match the original sprite.
    The triangles for this calculated mesh are then broken up into individual gameobjects with their own colliders.

    It plays nicely with scaling and rotating!

    there are tweak-able parameters that can control the minimum angle and area of the generated triangles!

    generated fragments inherit the velocity of the original object

    Future Plans:
    I'm really hoping to improve this so that the sprites break into voronoi regions rather than just riangles, this will make them look more like real fragments.

    I also need to make this multithreaded... for now there is a perceptable pause when something is destroyed.

    $2014-03-18 19_41_56-Unity - Level.unity - UnityTriangleNet - Web Player_.png $2014-03-18 19_42_25-Unity - Level.unity - UnityTriangleNet - Web Player_.png $2014-03-18 19_43_07-Unity - Level.unity - UnityTriangleNet - Web Player_.png
     
  2. Micha-Stettler

    Micha-Stettler

    Joined:
    Jun 11, 2009
    Posts:
    167
    Great Idea!
    Its alot of fun to play around. :D
     
  3. indiegamemodels

    indiegamemodels

    Joined:
    Jan 25, 2012
    Posts:
    269
    Very fun indeed!

    Do you plan on making a full game using this as main feature, or more an Asset store plugin?
     
  4. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Possibly both. For now it's just a fun project that I hope to learn from. In a perfect world I'll get something out of it that's good enough for the asset store and possibly some cool game mechanics :D
     
  5. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Got around to making a sweet update this weekend!

    Now instead of just shattering into triangles, the sprites can be shattered into voronoi pieces which look much cooler! The only downside is for whatever reason certain sets of points cause the triangulation algorithm to fail.

    Next on my list is to add random sampled points to the triangulation to get more varied pieces. For now it just uses the collider points as data for triangulation. I can probably use this to solve the occasional errors I'm getting now. Like if an error is produced from the existing set of points, add another random point.

    Webplayer is updated to better showcase features!

    $2014-03-23 20_07_20-Unity - Level.unity - UnityTriangleNet - Web Player_.png
     
  6. VonPro

    VonPro

    Joined:
    Jun 17, 2015
    Posts:
    1
    Hello there! Can I ask your source code so I can study it an implement it on my game. Thanks!
     
  7. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Never developed this further than what you see but if I still have the project files around put them up for you
     
  8. LochieWestfallGames

    LochieWestfallGames

    Joined:
    Aug 25, 2015
    Posts:
    7
    If you could publish this it would really be helpful to me too. If you don't have the code i would like to know.
    Thanks.
     
  9. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I actually totally re-did this recently. It could probably use a bit of cleaning up but maybe I'll post it on GitHub sometime this week
     
  10. LochieWestfallGames

    LochieWestfallGames

    Joined:
    Aug 25, 2015
    Posts:
    7
    ok when you do that could you leave a link? thanks
     
  11. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    neonblitzer, vvalente and hippocoder like this.
  12. LochieWestfallGames

    LochieWestfallGames

    Joined:
    Aug 25, 2015
    Posts:
    7
  13. LochieWestfallGames

    LochieWestfallGames

    Joined:
    Aug 25, 2015
    Posts:
    7
    If i ever use this in a project do you want credit?
     
  14. LochieWestfallGames

    LochieWestfallGames

    Joined:
    Aug 25, 2015
    Posts:
    7
    You should put this on the asset store. All the other versions of this are way too expensive and the cheap / free ones are horrible. But i won't judge if you don't.
     
  15. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Nope no credit necessary :) I'd love to see whatever you end up using it for though
     
    hahahpizza likes this.
  16. LochieWestfallGames

    LochieWestfallGames

    Joined:
    Aug 25, 2015
    Posts:
    7
  17. LochieWestfallGames

    LochieWestfallGames

    Joined:
    Aug 25, 2015
    Posts:
    7
    a project i have been working on recently is a game called bap. haven't had enough time to use this in it but it should be on the app store soon.
     
    TheValar likes this.
  18. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
  19. ismaelnascimentoash

    ismaelnascimentoash

    Joined:
    Apr 2, 2017
    Posts:
    30
    Very good !
     
    TheValar likes this.