Search Unity

Destructible 2D ☄️ Dynamic Sprite Destruction

Discussion in 'Assets and Asset Store' started by Darkcoder, May 29, 2014.

  1. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
  2. trudeaudm

    trudeaudm

    Joined:
    Apr 17, 2013
    Posts:
    116
    Hello!

    Do you plan on making this compatible with Unity3D's SpriteShape?
     
  3. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I will investigate implementing this in a future version. I just submitted a major update to Destructible 2D that makes many improvements to the code, and it will make implementing features like SpriteShape much easier.
     
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Hey everyone,

    Version 3.0.0 of Destructible 2D was just released, and is currently 50% OFF!


    This is a major update. If you're using version 2.X.X of Destructible 2D then don't recommend you update, because you will have to update most if not all of your GameObjects to use the new settings.

    This update simplifies a lot of component settings, has cleaner internal code, and includes some new features, including:

    Scorch Marks - Instead of just damaging the alpha of your destructible sprites, you can now paint the RGB values too, allowing you to add scorch marks. This will be expanded upon in future versions.

    Tutorial Scenes - The tutorial demo scenes are now fully separated from the showcase/game demo scenes. Each tutorial scene goes through each feature step-by-step.

    Improved Fracturing - The new D2dFracturer component automatically calculates the optimum fracture count, and produces much higher quality splits than before.

    More updates to come soon, enjoy!
     
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Hey everyone, here's a new tutorial video covering the basics in Destructible 2D version 3.0.0


    I also added some new pictures of some of the new example scenes:


    Space Shooting Game Example (Included)
    • Spaceship controller with thruster and gun controllers
    • Bullet impact detection
    • Asteroid impact damage+ scorch marks
    • Asteroid automatic splitting into smaller pieces
    • Infinitely tiling background


    Car Racing Game Example (Included)
    • Car controller with top down wheel physics
    • Collision impact detection
    • Car impact damage + scorch marks
    • Infinitely tiling background

    Forest Game Example (Included)
    • Animated destructible sprite
    • Mouse + Finger slice action
    • Tree automatic splitting from slices
    • Tree automatic detaching from solid ground
     
  6. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Hey everyone, here's a sneak peak of a new spaceship demo scene that will be in the next version of Destructible 2D!

     
    Chizel likes this.
  7. Chizel

    Chizel

    Joined:
    Dec 29, 2018
    Posts:
    9
    Total N00b here. I bought the asset but when I try to view the demos I am getting 5 errors! I am relatiely clueless with Unity for now but am learning. Is there a link i am missing or a setup. I Downloaded the asset, imported, and created a project using the D2D kit.
    CS 0117 & CS1061
    Sprite Rendered does not contain def for draw mode
    Edge collider does not contain def for edgeRadius
    Matrix 4x4 does not contain def for Translate.

    Unity is right out the box + D2D

    Plz help. :) I can't wait to use. Will continue to feeble figure out if some assembly thing is the culprit.
     
  8. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Can you tell me the exact version of Unity you're using? (shown at the top, or Help/About Unity)

    The latest version of Destructible 2D was submitted for Unity 5.6.6f2, which is the latest and possibly last version of Unity 5.
     
  9. Chizel

    Chizel

    Joined:
    Dec 29, 2018
    Posts:
    9
    Thank you for quick response.
    :D
    I am using Unity 5.5.4p4 Personal (64-bit).
     
  10. Chizel

    Chizel

    Joined:
    Dec 29, 2018
    Posts:
    9
    Nice Lighting of the laser and explosions. If you don't mind me asking, How did you accomplish that?
     
  11. Chizel

    Chizel

    Joined:
    Dec 29, 2018
    Posts:
    9
    Updated to the 2018.3.0f2 and everything seems to be working now. Thank you Again for prompt response. I am not sure why Unity didn't update to this version. I updated it yesterday before running anything... oh well. problem is solved. I can't wait to start learning and building now.
     
    Darkcoder likes this.
  12. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Great! Let me know if you encounter any other issues!
     
  13. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Hey everyone, today is the last day to get Destructible 2D at half price!


    If you already have it then stay tuned, there's an awesome update coming soon!
     
  14. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    Hi!

    I am a beginner of unity.
    I use the corgi engine, which has a poolable bullet system.

    The space shooter tutorial works with instantiation.

    Question: How can I make the spaceship bullets poolable...(I want to shoot destructible bullets with the retrocopter character of corgi)?

    When I try to use the spaceship bullet in the corgi engine it works only one time, after that an error occours (see below).
    From the corgi side I do nothing wrong, because I had a similar problem before (forgot to add the corgi "poolable Object" component to the bullet..but when adding this component to the spaceship bullet it works only one time)



    MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    MoreMountains.Tools.MMSimpleObjectPooler.GetPooledGameObject () (at Assets/CorgiEngine/ThirdParty/MMTools/ObjectPool/MMSimpleObjectPooler.cs:60)
    MoreMountains.CorgiEngine.ProjectileWeapon.SpawnProjectile (Vector3 spawnPosition, Int32 projectileIndex, Int32 totalProjectiles, Boolean

    Thanks
     
    Last edited: Jan 3, 2019
  15. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Bullets in Destructible 2D use the D2dBullet component. This component automatically destroys the current GameObject (bullet) when it hits something, and if not the D2dDestroyer component will destroy it in 0.75 seconds from being shot. If Corgi has a poolable bullet system then I recommend you use that instead of D2dBullet + D2dDestroyer, all you have to do to make destruction work is spawn the same "Explosion Prefab" (e.g. Spaceship Bullet Explosion) on impact. Combining D2dBullet + D2dDestroyer with corgi's pooling system would require you to modify the code of these two components to trigger pooling instead of destruction, but I don't have Corgi and don't know if this is easy to do or not.
     
  16. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    Thank you!
    Using the red Expolsion prefab works as a bullet!
     
    Last edited: Jan 5, 2019
    Darkcoder likes this.
  17. DavidJares

    DavidJares

    Joined:
    Dec 18, 2016
    Posts:
    50
    Hi. I am a new to Destructible2D. I already really love it a lot. Can anyone help me how to make the splitted parts of my kinematic-destructible-Object switch to being Dynamic ? So that the main Object can be controlled with steady velocity, but so that split off parts can fall down with gravity ? I searched through the 2D-Splitter-script, but I am really not sure where to inject that functionality ? The way it normally seems to work is that the splitted parts inherit the same behaviour like the original part. Best regards, and thank you very much for your help. David :D
     
  18. DavidJares

    DavidJares

    Joined:
    Dec 18, 2016
    Posts:
    50
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I recommend you use the "Make Destructible (Preset: Dynamic Detachable)" when making your destructible object (click the gear icon at the top right of your Sprite Renderer), this automatically sets it up with the features you describe, you just need to move the child Fixture to a solid part of your sprite. You can view THIS tutorial that shows you how to do this.

    I'm currently overhauling the documentation files of all my assets. For the D2dDestructible component you can just hover the mouse over any setting and you'll see the same thing that you would find in the documentation.
     
  20. MikePauza

    MikePauza

    Joined:
    Jan 6, 2014
    Posts:
    11
    Hey Carlos,

    Just started playing with the demos. Got your stamping working well with a custom voronoi png for small and thin objects FYI, but your fracture code is much better in general for fracturing I think! ;)

    BTW, working on an asteroids zero gravity type game and noticed on the fracture demo that attaching the retain velocity script only kind of works. Something weird is going on it looks like. Also, this is not the problem but it would be better for velocity inheritance to have a rotational term like this (VelocityChild = VelocityParent + (DistanceBetweenChild&ParentCenters * RadianAngularVelocityParent)).

    Hope this helps Carlos. Like the asset! -Mike
     
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Glad the stamping worked out for you! The D2dFracturer indeed also implements voronoi and works well for the general case, it doesn't optimize the nearest point search though, so it may not be the best if you have many fracture points, I also want to implement actual anti-aliasing with it so the edges look better.

    As for D2dRetainVelocity, it sounds like you might be describing the main issue where an object impacting a sprite will already have imparted its impact force on the main rigidbody, and any children created after this due to fracturing will have no knowledge of this impact, and will just carry on using the parent's velocity. This isn't so noticeable in the example scenes because they have gravity and the impacting object will often carry on and impart different forces on each child, but this is unlikely to happen in 0g. As you suggest, some kind of extra code or component to simulate this breaking force would be required.
     
  22. MikePauza

    MikePauza

    Joined:
    Jan 6, 2014
    Posts:
    11
    Thanks Carlos.
     
    Darkcoder likes this.
  23. Ktulian

    Ktulian

    Joined:
    Apr 6, 2014
    Posts:
    8
    Will this be getting the new ECS updates?
     
  24. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    It's currently designed to target Unity 5.6.6f2 all the way to the current version, and I don't want to write the code twice, so not yet. Most of the heavy code in D2D is the splitting, which is already quite optimized and likely wouldn't see much benefit from ECS.
     
    Ktulian likes this.
  25. Bit9Labs

    Bit9Labs

    Joined:
    Mar 24, 2013
    Posts:
    9
    I'm messing around with the demo scene 02 Edge Collider and 03 Polygon Collider.
    1. I'm using the castle and stamp as provided.
    2. I've set up a simple sprite with a Rigidbody2D set to trigger.
    3. I've placed this sprite fully behind the castle
    4. I've added a script with Debug.Log in OnTriggerEnter2D and OnTriggerExit2D
    When ever I MouseUp in the vicinity of the simple sprite I get from one to multiple debug messages in both the trigger exit and enter. I was wondering if you knew what was the cause of this? I'm assuming the collider gets reactivated or replaced every time a stamp is placed on the castle?

    My goal is to only have a single trigger exit iff the trigger sprite is fully uncovered from one or more stamps on the castle.
     
  26. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    While colliders are reused/pooled where possible, destroying a sprite usually increases the complexity of the collision shape, and this often leads to more colliders being required. This is especially true when using lower collider CellSize settings. You will probably have to write some additional code to account for this based on your requirements. The D2dDestructibleSprite.SampleAlpha method may be of use.
     
  27. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    I don't know if this have been answered before, but is it ready to work with multiplayer games?

    How to synchronized the destruction across other players?
     
  28. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    There are no multiplayer features built into this asset, and I have no plans to include any. To add support for this you will have to manually manage the synchronization of the D2dDestructible class data (e.g. AlphaData, AlphaWidth, AlphaHeight). If you're just damaging/healing basic static or dynamic objects then that's all you will have to do, and it should be quite easy. However, if you begin using more complex features like splitting or fixtures, then it becomes more complex.
     
  29. Bamboy

    Bamboy

    Joined:
    Sep 4, 2012
    Posts:
    64
    Hey there Darkcoder! I just upgraded my project from 2017.4.22 -> 2018.3.11. Scorch marks sound very appealing for the kind of game I'm making. Is there, or can you make an upgrade guide from v2 -> v3? I don't have that many errors since I'm only using the alpha feature of your tool with my own collision system on top of that.
    Game: https://bamboy.itch.io/asteroidians
     
  30. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    There's no upgrade guide, mainly because V3 was a rewrite, and so you have to set up most features again from scratch. I did arrange all the demo scenes to be in sequence to clearly show and describe how to use each feature though, so it should be fairly easy to understand how to use all the new features.
     
  31. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    @Darkcoder Is there a way to save and load a scene with partially destroyed 2d objects? Is there an API for serializing the destruction?
     
  32. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    There's no automatic way to do this, unless you use some kind of saving asset that automatically saves everything. To do this manually you must at minimum save the destructible.AlphaData, AlphaWidth, and AlphaHeight. Depending on the features you use you may need to also store the current sprite, alpha rect, etc.
     
  33. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    @Darkcoder I am using a 2D Buoyancy effector in my scene. But it seems that the regular Density param from BoxCollider2D and such are not present on the D2D Polygon collider? I'm wondering how to make it work? For example, my buoyancy effector is 'lava' with a density of 10 - there is no way of making the fractured pieces sink very slow (it seems) by nearly matching the fluid density?
     
  34. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    There's currently no Density setting. To add it, D2dPolyconCollider.cs must be modified (inside Refresh, and AddCollider).

    I plan to update D2D to a more recent version of Unity which includes the Density setting.
     
  35. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    Alright, thanks for your reply! Looking forward to it.

    A different question: is it possible so that stamping on an objects add a decal? Like a blood spatter stamp that doesn't "heal" but just adds the spatter shape/ texture on top of the Destructible sprite?
     
  36. oxa89

    oxa89

    Joined:
    Aug 29, 2014
    Posts:
    15
    Hello, I am thinking of buying this asset but first I need to ask you if it fits my needs.
    I have sprites that are made mostly out of polygons (some are made of irregular shapes). Can I split those sprites in advance on those polygons and then rotate polygons independently?
     
  37. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Yes, check out the "26 Scorch Marks" demo scene. This subtracts a white texture to make black marks, but you can use a cyan texture which will leave red.


    Yes, sprites will automatically split when you add the D2dSplitter component. In your scenario you can manually click the "Try Split" button, which will perform the split in the editor, then you can move the separate parts around.
     
    oxa89 likes this.
  38. oxa89

    oxa89

    Joined:
    Aug 29, 2014
    Posts:
    15
    And can I cut the sprites on specific lines?
     
  39. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    The "Try Split" button mentioned previously will split all pixel 'islands', there's no ability to specify which islands you want to separate. If you want to do this you can either slice your sprite up in a specific order such that you get the islands you want when you want them, or you will have to modify the splitting code to reject splitting islands that don't meet your criteria. This sounds like a very project specific feature though, so it won't be implemented in destructible 2D.
     
  40. oxa89

    oxa89

    Joined:
    Aug 29, 2014
    Posts:
    15
    What are those "pixel islands"? I need to cut it to polygons like on this picture:
    https://www.google.com/search?q=pol...AUIDigB&biw=1920&bih=944#imgrc=erlZGC10vH2zqM:
     
  41. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Pixel islands are areas of your sprite that are completely separated, and have no solid pixels connecting them. When you get pixel islands like this, Destructible2D can split them into separate objects. Your example image is just one solid image with no pixel islands, this kind of image cannot be split.
     
  42. oxa89

    oxa89

    Joined:
    Aug 29, 2014
    Posts:
    15
    What if I put empty line between those polygons? Just 1px width line
     
  43. jarbleswestlington_unity

    jarbleswestlington_unity

    Joined:
    Dec 6, 2017
    Posts:
    32
    I'm trying to use a pathfinding plugin (a* pathfinding project) and their code expects a single collider for dynamic obstacles, but destructible objects have multiple colliders.

    Do you have a suggestion for what to use instead of a collider.bounds? I read you say you use a sprite renderer but I can't use getComponent<SpriteRenderer>() to access it and I can't seem to get a mesh.bounds either
     
    Last edited: May 7, 2019
  44. jarbleswestlington_unity

    jarbleswestlington_unity

    Joined:
    Dec 6, 2017
    Posts:
    32
  45. RavaGames

    RavaGames

    Joined:
    Sep 28, 2013
    Posts:
    2
    @Darkcoder Is there a way to use density texture in v3? I used v2 for a while and then updated to the rewrite and couldn't find any references to it.
    It's not super crucial, but it would definitely spice things up to be able to set the densities instead of every part of an item being identical, but I guess it does come with a performance hit to compare the tex.

    Also would it be simple to expand on the scorch stamping so instead of subtracting you could replace the pixel entirely? This would allow for more flexible stains/wounds, since subtraction depends on the original colour and all.
    (Made with same cut.)
     
    Last edited: May 22, 2019
  46. Haykys

    Haykys

    Joined:
    Mar 12, 2019
    Posts:
    13
    Any idea why Destroy(otherGameObject) is not destroying the gameobject when passing through OnTriggerEnter2D ? when I remove `Make Destructable` it works as intended
     
  47. Haykys

    Haykys

    Joined:
    Mar 12, 2019
    Posts:
    13
    Nvm had to destroy the parent gameObject as the colliders are created as child. This asset looks awasome and powerful but I feel it could use better documentation as how to work with it inside scripts, cause I have little idea how to manipulate stuff inside script
     
  48. jarbleswestlington_unity

    jarbleswestlington_unity

    Joined:
    Dec 6, 2017
    Posts:
    32
    @Darkcoder Do you recommend any path-finding programs that pair well with destructible? I bought the highest rated one (A* pathfinding project) but it isn't compatible with having multiple colliders in one Gameobject

    Figured it out, a meshRenderer seems to substitute nicely, if you come back to this project maybe that will help
     
    Last edited: Jun 10, 2019
  49. elZach

    elZach

    Joined:
    Apr 23, 2017
    Posts:
    48
    Hey just a heads up: I bought and downloaded your asset and imported it to a project running in Unity 2019.2.0b4.
    Tutorial scenes were not working as intended, after a bit of comparison between the objects I noticed that the default material in Resources/Destructible 2D was set to use Sprites/Default instead of Destructible 2D/Default.

    Might want to check if that's an issue with your latest build.

    Also there seems to be a problem with cropping on sliced sprites

    Is there a reason why D2D can't handle Sprites which are set to FullRect instead of tight?
    If using those sprites D2D produces a lot of errorcodes. FullRect would be more benefecial to use when you're working with sprites which have to fit the same space despite making use of different shapes. (Spawned levelshapes, tile-like objects etc) Edit: Errorcodes also seem to be caused by cropping
     
    Last edited: Jun 7, 2019
  50. elZach

    elZach

    Joined:
    Apr 23, 2017
    Posts:
    48
    @Darkcoder hey, it has been a week, did you have a chance to have a look at the issues?