Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Exploder [RELEASED]

Discussion in 'Assets and Asset Store' started by reindeer-games, Jul 12, 2013.

  1. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    1. I've tried exploding the ships first, and it still doesn't work.
    2. I have a couple of purchased ship models that have been working properly with Exploder for months. I haven't changed them at all.
     
  2. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    924
    Hello reindeer,
    You had mention awhile ago about the integration of particles being attached to the fragments? Like smoke or fire....
    Have you had any update on that.
     
  3. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hm, that's really weird, but if it was working properly for months something has changed. Maybe different Exploder settings? It might a be a bug in Exploder but it is really hard to guess what can be the problem. Can you send me a screenshot of exploder settings (inspector view)?
     
  4. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Yes, I did mentioned it. I haven't updated it yet, I was very busy with my day job and didn't have much time for exploder for a while, but things are getting brighter.
     
  5. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    You've got a PM. :)
     
  6. Polygans

    Polygans

    Joined:
    Apr 19, 2009
    Posts:
    79
    Hi Reindeer

    quick question about the explosion of the animated character. I saw that you just put a simple capsule collider on there. I tried replicating that with another animated character of mine but it doesn't work. Do you might know why? Is there maybe some other adjustments I have to do?

    Thanks a bunch :)
     
  7. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi, it is not really about colliders, the object (animated character) just has to be tagged with "Exploder" or has to have Explodable script on it. Then you just create ExplodeObject and call Explode() function in the radius with your object. If you still have problem with explosion, it might be related to the model, make sure that your character is properly closed mesh. If you have more problems, send me a screenshot to PM with your inspector settings.
     
  8. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi, sorry, I must overlooked your post, but I can't find any post about rewinding. You are using some kind of library for rewinding? I can't see now how is the rewinding related with Exploder, can you please explain more?

    RG
     
  9. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    735
    Oops sorry. I'm using exploder and rewinder. I accidentally posted in wrong thread. Feel free to delete post
     
  10. Polygans

    Polygans

    Joined:
    Apr 19, 2009
    Posts:
    79
    Well it was, because in this case I didn't get any collision so the explode function was never triggered. Fixed that now tough.

    Do you happen to know why there is some slight jitter of the fragments after you explode an animated character?
     
  11. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Oh, I see, I think I misunderstood your question, good to hear it works now.

    The slight jitter is probably caused by baking the animated character. Before the explosion the animated character (skinned mesh) is baked into the regular mesh, it happens in the first frame of the explosion, then I work with the mesh as with any other meshes.

    http://docs.unity3d.com/Documentation/ScriptReference/SkinnedMeshRenderer.BakeMesh.html

    I believe the jitter is cause by this, but I haven't investigated it much because it happens very quickly and most of the people don't notice it at all. But anyway I will look if I can prevent it.

    Regards.
     
  12. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    26
    hey, i just bought it. I am not sure how to attach it. I am doing everything per script (c#) in my game, no manual attaching tags or components to game objects, what is the best way to explode a particular gameobejct... and attaching the exploder script to it first by script.... having an exploder script already and telling it to explode a certain object.
     
  13. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi, thank you for buying Exploder!

    I just made a script that creates a cube and exploder from script and explode on pressing space:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class testScript : MonoBehaviour
    5. {
    6.     private ExploderObject exploder;
    7.  
    8.     void Start()
    9.     {
    10.         // create cube object
    11.         var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    12.         cube.tag = ExploderObject.Tag;
    13.         cube.transform.position = new Vector3(0, 5, 0);
    14.  
    15.         // create exploder object
    16.         var exploderObject = new GameObject("Exploder");
    17.         exploder = exploderObject.AddComponent<ExploderObject>();
    18.         exploderObject.transform.position = cube.transform.position;
    19.     }
    20.  
    21.     void Update()
    22.     {
    23.         // explode the cube on space
    24.         if (Input.GetKeyDown(KeyCode.Space))
    25.         {
    26.             exploder.Explode(OnExplosion);
    27.         }
    28.     }
    29.  
    30.     void OnExplosion(float timeMS, ExploderObject.ExplosionState state)
    31.     {
    32.         if (state == ExploderObject.ExplosionState.ExplosionFinished)
    33.         {
    34.             Debug.Log("Cube just exploded!");
    35.         }
    36.     }
    37. }
    38.  
    Let me know if you have any more problems.
     
  14. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    26
    ok thanks works for one box, but how can I reset the exploder object so i can use it again for another box?

    I tag the boxes right before I explode them too, not when I create them, cause I need control over which ones explode.
     
    Last edited: Mar 18, 2014
  15. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi, this is modified version where I create 20 cubes and move the exploder object to another cube on space. The trick is to disable ExplodeSelf.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class testScript : MonoBehaviour
    5. {
    6.     private ExploderObject exploder;
    7.     private int explosionNumber;
    8.  
    9.     void Start()
    10.     {
    11.         // create 20 cube objects
    12.         for (int i = 0; i < 20; i++)
    13.         {
    14.             var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    15.             cube.tag = ExploderObject.Tag;
    16.             cube.transform.position = new Vector3(i*2, 5, 0);
    17.         }
    18.  
    19.         // create exploder object
    20.         var exploderObject = new GameObject("Exploder");
    21.         exploder = exploderObject.AddComponent<ExploderObject>();
    22.         exploder.ExplodeSelf = false;
    23.         exploder.HideSelf = false;
    24.         exploder.Radius = 0.1f;
    25.         explosionNumber = 0;
    26.     }
    27.  
    28.     void Update()
    29.     {
    30.         // explode the cube on space
    31.         if (Input.GetKeyDown(KeyCode.Space))
    32.         {
    33.             exploder.transform.position = new Vector3(explosionNumber*2, 5, 0);
    34.             exploder.Explode(OnExplosion);
    35.             explosionNumber++;
    36.         }
    37.     }
    38.  
    39.     void OnExplosion(float timeMS, ExploderObject.ExplosionState state)
    40.     {
    41.         if (state == ExploderObject.ExplosionState.ExplosionFinished)
    42.         {
    43.             Debug.Log("Cube just exploded!");
    44.         }
    45.     }
    46. }
    47.  
     
  16. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    26
    now it works great, thanks had to use radius 0.5 tho for some reason
     
  17. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,646
    Thanks for the code. :D
     
  18. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    26
    is there a way to acess all the fragments to apply forces to them? are they all children of the exploder?
     
  19. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    The fragments are children of "FragmentRoot", you can access all your active fragments after explosion. Please take a look into one of the example scripts.

    Exploder/Examples/HowToGetActiveFragments.cs.

    You will get list of all active fragments and you can apply force to them as you want, they are just game objects with rigid bodies.
     
  20. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    26
    now... the second bomb after each explosion throws around the pieces like it should (the first one not always tho)

    but now I have a bizzare bug: sometimes the boxes instead of fragmentating simply become physical... so odd that. just one big fragment that is like the original box.

    is there any way to be using FragmentPool outside onExplosion fragments?
     
  21. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    1. If you see a box becoming physical into one big fragment, it probably means that the box is on the edge of exploder radius and there are no more fragments to allocate, more explanation on this picture

    $exploderRadius.jpg

    2. FragmentPool is an important part of Exploder, it recycles fragments for each explosion and ensures high performance of the system, you cannot remove it. However you can get all your active fragments and duplicate it, than you can use the duplicates as you like. But it would be better if you can explain me what you are trying to achieve, then I can give you some advice.
     
  22. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    26
    are you saying the target frags are all the fragments spawned at all and if it's over it will only spawn one each?

    they are very close to the explosion center.

    I ve got got a randomly generated level with many boxes, and you can blow up the boxes and their fragments will stick around. most of the time only 1 or two boxes will be blown up so I am not worried about performance... I am using mesh colliders too. so how do I fix this? making higher target fragments doesn't seem to do anything but make it more lagy. but the problem with the 1 fragment returns after a few boxes.
     
  23. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    26
    ok it's fine now, I just increase the target fragments by 10 every time and it seems to work
     
  24. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Great!
     
  25. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    26
    how do I access FragmentPool?
     
  26. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Please look at the example script:

    Exploder/Examples/HowToGetActiveFragments.cs

    Regards,
    RG
     
  27. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    26
    I tried that and I always get
    The name `FragmentPool' does not exist in the current context

    or Type `ExploderObject' does not contain a definition for `FragmentPool' and no extension method `FragmentPool' of type `ExploderObject' could be found (are you missing a using directive or an assembly reference?)
    if I try exploder.FragmentPool
     
  28. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    I think it is because you have a namespace conflict, FragmentPool is in namespace Exploder and there is also an member object Exploder in your class,
    you can rename Exploder to something else or you can you can use global namespace:

    Code (csharp):
    1. var list = global::Exploder.FragmentPool.Instance.GetActiveFragments();
     
  29. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Yeah...I think still have an issue with this.
    What I think I see happening is that the farther away from gameobject 'center'? centroid? that the exploder object is, the less fragments I get.

    What I see is that an exploder instance is created...with a small radius. I have a gameobject (largish?) either straddling that radius or right at the edge of it. I will often get the gameobject cut only in half. If the exploder object is closer - I get more fragments.
    This is when there are NO other objects in the radius and my pool is not even close to being utilized...

    is that possible?
     
  30. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Yes, I believe it is possible, because Exploder tries to behave as a grenade explosion - closer to the center you are, more fragments you will get. If it is a problem in the future I can add another public parameter to fine tune the fragments allocation (from current behavior to ignoring distance from radius).
     
  31. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Ahhh...that explains a few things (thanks!!)
    Gotcha.
    In my case, I am implementing a damage system behind the scenes - so when I ask exploder to explode anything in radius- I want it to explode 'real good' anything in the radius.
    I'm pretty sure I can tweak the code myself to do what I want ...can you point me at a line number range to start poking around?
     
  32. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Okey, you can try to tweak the code, the code where it happens is called in function (ExploderObject.cs)

    Code (csharp):
    1.  bool Preprocess()
    and
    Code (csharp):
    1.  GetMeshList()
    the output of the allocation algorithm is array levelCount[] which contains number of fragments for each level. Before the explosion the radius is split into levels (1...n) where level 1 is the most closest to the center. And each object has assigned this level number, so in the explosion phase the cutting algorithm look into level 1 (levelCount[1]) and gets the number of cuts for this level, then it continues to second level, etc. So you can start playing with this variable, I think when you equally redistribute values in levelCount[] you can achieve what you want, but I can't tell until I test it.
     
  33. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Perfect...thanks!!
     
  34. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Anyone have a technique to grab fragments and turn them into prefabs for later use?
    I really want to create some 'junk/trash' and exploding a mesh seems like a fine way to generate some appropriate meshes.

    I have paused scene and grabbed fragment and turned into prefab - but alas, no mesh filter comes with.

    I'm sure there is a way programmatically to do this....anyone got a technique in their back pocket?
     
  35. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    Ahh...a lightbulb just went off for me.
    I just realized that "Target Fragments" isn't "per exploded object" - it's overall target fragments for that explosion!!!
    I was soooo confused that an explosion with a small radius would produce a nicely chopped up set up meshes - but when I used a larger radius , the number of fragments per object was much smaller (chunking) regardless of how close an object was to the center of the explosion.

    That helps me steer around some issues and or tweak things to my liking.
    Tis a balancing act of performance and realsm....
     
    Last edited: Apr 5, 2014
  36. casperjeff

    casperjeff

    Joined:
    Apr 13, 2013
    Posts:
    333
    If anyone is interested I made some tweaks to Exploder to better suit my purposes.

    #1 - removed the 'level' based fragmentation so that when an object is designated to explode - it uses max fragments available as opposed to distance based (this was causing me issues with buildings where their centroid was far away but still within range - and they were either getting turned into single fragment or just 2 - which made it look unrealistic.
    #2 Changed to that it didn't use the 'center mass' of the objects to see if they were in range - instead used the colliders (and overlap sphere). This was because I needed a small explosion to be able to destroy a large object on occasion.
    #3 Added a damage system so that based on distance from exploder object - instead of 'exploding' arbitrarily, it would apply damage - and if health was low enough THEN explode.
    Lastly (#4) - added physics explosive force to objects within range that DIDNT get exploded (just took damage). Allowed my asteroids to move when near an explosion -

    You can PM me for info if you are interested in any of the above.

    @reindeer games - AWESOME asset!!!!

    [video=youtube_share;VySfBfv2V80]http://youtu.be/VySfBfv2V80
     
  37. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Great work!
     
  38. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    510
    i try to test the exemple scene on android device, it work fine in unity but didn t seem to explode on the device, anyone experience this?
    thanks
    toto
     
  39. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    924
    Has anyone figure out how to attach particles to the exploded fragments.
     
  40. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi,

    you are right, I just tried and after some testing I found a solution, Unity compiler does not like files with the same name even if the files are with different extension (c#, js). To fix it, just go to directories "DemoClickExplode" and "DemoSimple" and delete the ".js" file. Then it should work.
     
  41. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    510
    awesome work fine now, was wondering if it s possible to parent different cube or mesh into a skeleton, so only this part can explode while touching them that could give a better progressive explosion.
    i just test it quickly tagging them with exploder, but does seem to work that way...
     
  42. yandrako

    yandrako

    Joined:
    Dec 2, 2013
    Posts:
    26
    Hi!

    First of all, congrats for the plugin, its very useful!
    Im wondering, it is possible to make the reverse effect? What I mean is to explode a mesh, and then trigger an effect of collapsing all fragments into the original mesh again. If it is possible, could you point the path to do it?

    Thank you and continue with your great work
     
  43. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi, thanks!

    Implementation of reverse effect shouldn't be difficult, I would do it like this:

    1) First create a fragment recorder: some kind of buffer (list) of position/rotation/scale and time for each fragment, this can be part of Fragment class.
    2) Create an explosion and in Fragment Update() you can store every frame (or every n frame) transform information and time into the buffer.
    3) Limit the buffer so it will not bloat the memory, you can always clear the buffer on a new explosion and fill it for example 5 seconds after explosion every frame.
    4) Create a replay method where you will take items from the buffer (from last position to first), make some simple interpolation (lerp,slerp...) and assign the new transform information to the fragment piece.
    5) When you get to the first item in the buffer, hide the fragments, show the original model.
     
  44. cubaschi

    cubaschi

    Joined:
    Oct 23, 2012
    Posts:
    43
    Hi,

    first, love the package! Everythings runs smoothly in my game with the Exploder package.
    I have 2 issues though:
    1) I really need to set the TargetFragments per Object. I won't run into performance issues because I know how many objects and fragments there will be.
    I tried to set the Exploder collision sphere to tiny tiny 0.001f and chnage the fragments per object but my gameobjects are build from several primitives which I explode on after another and I don't get reliable results concerning the fragments count.
    Is there any way to do this?

    2) In my game a spaceship flies/crashes into objects floating in space. If I don't explode these, they are flung around by the impact of the spaceship/rigidbody. If I explode them, the spaceship seems to hit a wall and stops. What is happening at the moment of the explosion that might stop the rigidbody hitting the explode objects?

    Thank you very much in advance,

    Simon
     
    Last edited: Apr 27, 2014
  45. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi, thanks for using Exploder!

    Okey, I think more people would like to have this option, I will add it to next update, it will require a bit of refactoring.

    Hm, I am not sure why it is happening. Can it be because after explosion lots of fragments hit the spaceship, apply physics to spaceship rigid body and it brakes the spaceship velocity? Maybe you can try to change the spaceship rigid body to "kinematic" to see if anything has changed.
     
  46. cubaschi

    cubaschi

    Joined:
    Oct 23, 2012
    Posts:
    43
    concerning 2)
    Allthough I turned on destroy originalGameobject that didn't happen in time to not stop the path of the spaceship. I pause stepped the game and saw that the ship hit and moved the obstacle for one frame and then when the damage handler kicked in and started the exploder the collider of the original object stopped the movement allthough it allowed it before the explosion. I disabled the collider of the original object before exploding and it worked fine,

    simon
     
  47. cubaschi

    cubaschi

    Joined:
    Oct 23, 2012
    Posts:
    43
  48. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
  49. karmacomp

    karmacomp

    Joined:
    May 2, 2014
    Posts:
    43
    I bought Playmaker and Exploder. My game will utilize exploder a LOT. I plan on decimating a lot of objects. My problem is that I cannot figure out how to make exploder work within Playmaker. I admit, I am a total noob to Unity3D AND Playmaker, so any help is appreciated. There are no Exploder Playmaker demos to learn from. My main character will kick, punch and use non-violent devices to explode objects. When I try to add the explode action to a cube, for example, the cube explodes immediately and I don't even see the pieces of the cube. I did edit the three scripts as outlined in the manual.

    Mike
     
    Last edited: May 2, 2014
  50. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi Mike,

    I just created a simple playmaker demo from the "SceneSimple":

    1) Open SceneSimple demo scene.
    1) Add a cube to scene and attach playmaker FSM to it.
    2) Create MouseDown event.
    3) Create a new state called "Explode".
    4) In the "Explode" state open Action Browser and select "Explode".
    5) Specify the game object "Exploder" from scene hierarchy to "Explode" state.
    6) Add playmaker transition from State1 to Explode
    7) Hit play and click on the cube.
    8) See the explosion.

    $playmaker.jpg

    Regards,
    RG
     
unityunity