Destroy all your sprites using Destructible 2D. This feature packed destruction toolkit takes you game to the next level, adding new gameplay possibilities!
Destructible 2D has received regular updates for over 6 years. Thank you to everyone who was purchased, rated, reviewed, and provided feedback!
Sounds interesting, but I think there’s a problem with your webplayer demos as they’re not working at the moment (the sprites are black rectangles that don’t do anything). I’m on a Mac if that makes any difference.
I have a couple small questions I hope you can answer.
What determines which object will be parent or child if the object becomes split. Is it easy to make the parent always be the larger half?
Do objects keep and continue to run their script if split?
Is it easy to output a % of mass left on an object?
I want to use the remaining mass of an object as its health and want to make sure this is possible.
I like the fact that your destruction script can handle multiple kinds of cuts. I have not found another script that can do this. Most will ignore damage unless it passes through the entire object. It also seems to run faster than other code serving a similar function.
Right now the splitting is based on the position of the pixel ‘islands’ in scanline order, where the first encountered island will remain the original.
If you want to force the original to always remain the largest island, then open up Destructible2D/Required/Library/D2D_SplitCalculatior.cs and scroll down to line 109 and add the following:
fills.Sort((a, b) => b.Count.CompareTo(a.Count));
In the next version I’ll include an option in the inspector so you can choose between various sorting modes.
Yes, when a sprite is split, the original gets duplicated, so all scripts and settings will get copied over.
No, but this is a good idea. I’ll add it to the next version.
Thanks for the ideas! I’ll hopefully get the next version ready today or tomorrow.
Thank you for your quick reply. I am looking into creating a game that heavily relies on slicing of 2d objects. Part of the issue I have is that most if not all engines cannot do partial cuts like yours can, they either completely cut through the object, or don’t cut at all, they also seem to chug after a couple cuts where as yours seems like it will work great for mobile.
Ray ray = Camera.main.ScreenPointToRay(transform.position);
float distance = D2D_Helper.Divide(ray.origin.z, ray.direction.z);
Vector3 point = ray.origin - ray.direction * distance;
D2D_Destructible.StampAll(point, Size, Angle, StampTex, Hardness, Layers);
Okay so I was trying to pass a vector 3 position instead of a vector 3 screen position. Now I can laser through things all day. Going to have to figure out some tricks to make it work smooth on phone though.
So something that I am noticing is split is a very expensive action when I think many uses of it might just be visual rather than functional.
In my case I want a static mesh that when sliced, the smaller part becomes a full physics object that cannot be sliced and falls away. I think I may mess around with the code a bit and see if I can come up with a version that does something of the sort, In my case I want to be able to slice things on the iPhone, but the part that is smaller will be inconsequential other than the graphic of it flying off and will just drain processing power if it has a sophisticated collider and can still be cut when I no longer need it to do either.
But yea, if your camera is set to Perspective rendering then you would need to project the start and end points into 2D space. The only reason why I didn’t include a demo for this is that if your sprites are on a different Z position then the stamps can become unintuitive (e.g. it may appear to stamp the wrong areas on each sprite), so sticking to 2D only demos simplifies things.
Yes, slicing is pretty expensive because I first have to find all pixel islands. Right now I’m just iterating over each pixel and flood filling each region, perhaps there’s a much faster method. And once sliced the Sprite needs to be cloned and each AlphaTex needs to be generated, which can also be expensive.
As for slicing static sprites up and have the smaller pieces break off, this is actually a feature I added to the latest version, but I’m just waiting for the Asset Store team to accept the changes. I’ll send you an early copy of it to try out.
Awesome! I think this is everything I needed. Thanks for the support.
The ability to create dynamic objects from a static one is going to be great, can’t wait to start experimenting with it.
Added Solid Pixel Count and Original Solid Pixel Count variables to sprites.
Is this the % of mass left functionality I asked for : )
You can get a percentage (0…1) from: yourDestructibleSprite.SolidPixelRatio
If you’re using this on a sprite you’ve already set up before updating, then make sure you first select your sprite and choose ‘Recalculate Original Solid Pixel Count’ from the context menu.
Stalactites - This demo features the new ‘Breakable’ component, which allows you break static sprites into dynamic ones. If you click the mouse on the stalactites then you should be able to break chunks off the static sprite and have them fall onto the eggs.
Mothership - This demo features the upcoming ‘Fixture’ component, which allows you to associate a GameObject with a specific pixel on your destructible sprite. This means that if you split a sprite in half (e.g. a space ship), the game objects that are attached to pixels on the other side of the split will still be attached to the correct side. It also allows you to destroy objects that are attached to the destructible sprite (e.g. the engines and guns).
These demo scenes will all be included in the next version of Destructible 2D. Stay tuned for more!
The Fixture component is awesome. Super easy to place, I just made an object with a script, added the fixture component and then made the component a child of the breakable object. In my case I made a building with some lights. Cut the building and the lights roll with it.