Detonator, getting my head around the usage

I’ve recently started messing aroudn with the Detonator unity extension (The Explosion Framework) and unfortunatly the documentation on it is quite slim and I haven’t been able to deconstruct the example to get an understanding on how to call it via script.

What I’m basically trying to do is create exploding objects in the same way that the example shows, but instead of on a mouse click and location, I want to use a physical collision to trigger the explosion.

Im curious if anyone is aware of any more detailed documentation or tutorials on the usage of the Detonator?

You can use it in various ways, which are pretty standard Unity, so that’s probably why there isn’t much specific documentation.

For example, all of the example explosions are saved as prefabs. So a simple way would be just to instantiate one of the prefabs on collision.

This script from the overview docs would do it. Just attach it to an object and drag the explosion prefab you want into the explosion var… and watch it go boom on impact.

Thanks a lot that was extremly helpful. Im starting to get the hang of this whole transforming, destruction and all that stuff.

I think I still have a timing issue or perhaps some collision settings need adjusting but there is a trigger in the detonator scripts that is “Explode on Start”, which I think needs to be of when you are going to have it explode on collision. However when its off the explosion doesn’t happen, but rather it simply vanishes (aka is destroyed by the script).

Im guessing this has to do with the fact that the object is colliding with the floor as im using the script concurrently with other scripts where I fire a sphere object from a spawn point (aka my fireball).

In any case you got me going in the right direction, so just wanted to say thanks.

Well I got the object to explode, but it appears that its still exploding when it spawns rather then waiting until it actually collides with something. Turning the trigger “explode on start” prevents the actual explosion but not the destruction of the object so I think there is some unexpected collision happening, perhaps with the floor or with other objects around it… though I tried putting the object in the air when the game starts and it still just vanishes…

still new to unity so im certain Im doing something wrong, but in any case… back to the tutorials!!

I think you’re just mixing up two possible methods a bit.

First method, is you just create an object in the editor, and attach a script that checks for impact. When you press play and it hits something, the script creates a new detonator on the fly, and it blows up right away (because of explode on start).

Second method, is you put the object in there and add the detonator yourself in the editor. Then you have to turn off “explode on start”. This time when you hit play, and your script detects a collision, it just needs to tell the existing detonator to explode.

The script I linked uses the first method, which is a bit easier to set up.
It’s correct to have explode on start checked, but make sure you don’t have an explosion attached to the object itself. It should be dragged into the “explosion” variable of your script.

Here’s a quick set up:

-Make a big stretched cube as a surface to drop a bomb on.
-Make a capsule to drop on to it. Position it above the cube and add a rigidbody so it will fall.

  • Go to assets->create->javascript, click edit, and paste in that script. Save it.
  • You should see the new script in the project view. Rename it “ExplodeOnImpact”
  • Drag the script onto your capsule in the hierarchy view.
  • Now select the capsule. In the inspector you will see it has an ExplodeOnImpact script. Under the field “script” will be a field “explosion”.
  • In the project view, under detonator, prefab examples, is a prefab for each type of explosion. Pick one and drag it over the “explosion” field in the capsule’s inspector. This tells that script what to create when it detects a collision.
  • That should do it - press play.

Hope that explains it - you’ll come across much better explanations of the concepts in the docs, but sometimes they’re not all in the same place.

Ah your right I was mixing up the two methods.

Your method definitly is a bit easier to control and it worked like a charm… more importantly i think I understand the principle on how it all works.

One question though regarding collision detection in general.

When you have an object like the base cube which has collision added to it. And then the capsule that has Rigid body on it. There appears to be an assumption (rightfully) that any time the two come into contact with each other a collision takes place.

My question is, how do you place one collision on an object with another collision and avoid collision.

Mean what if I want the capsule to be placed on the cube and wait for something to hit it before it explodes without exploding as a result of being in contact with the cube?

Im assuming this will have to be scripted with some sort of exception. Don’t feel like you have to help me, but I figurie this is probobly a useful post for someone who does a seach on the usage of the script so it might be helpful for others in the future to expand it a bit.

Here is a scenario for which I used it and I found an alternative method (a work around for this).

In my scenario I had an Avatar shooting projectiles at objects to cause them to explode so rather then placing the detonate on the object that shall explode I placed it on the bullet the avatar was firing. This had the effect of causing the explosion as the bullet collides with the object (though the object itself didn’t explode but rather just went flying). I solved that problem by removing gravity from the object (in which case it just explodes rather then goes flying) though this is still not a great effect as objects that you place on that object have wierd gravity effects.

So the requirement to be able to place an objection on the ground without exploding until something else hits it I imagine is one most people would have with the use of this AMAZING detonation effect.

Well, as usual there’s a bunch of different ways you could go about it.

A simple way, would be to tweak that script so that it checks what you collided with. Then you just need to think of some property of your game objects, that tells you if they cause an explosion or not, and wrap your code in a simple test.

A more useful way, in most games, is to make the default situation no damage. So you would not use that script on the target, but you have one on the projectile. It then checks the collision, and tells anything it hits “you took damage”. This is demonstrated in the FPS Tutorial part 2.

extremly helpful thanks… This has solved a lot of my questions and definitly shined a big lamp on many of the principles…

Big Thanks!

Dear Alric,

Huge thanks for your excellent explanation!