Short Tutorial: Exploding Objects.

Here’s a short tutorial and demo file showing how to make exploding objects in the blender game engine.
It’s a very basic technique and uses only logic bricks and normal Blender methods.

And a blend file with the exploding cup in it:
exploding_object.blend (519 KB)

EDIT:
If you want more realism you can use the cell fracture addon as shown in this tutorial:

The only problem there is that you’ll have a lot of objects so it’d be better to use a python script to add them rather than manually adding them with empties.
Have fun with that one! :slight_smile: I may write the script if I decide to use it in my own project…

OK, I finished the script for real time shattered cell simulation:

I’m no math genius so you should make sure the shattered version of the object is placed as near to the zero origin xyz= [0.0,0.0,0.0] on the inactive layer as possible. The script will use the chunk’s offset from zero as a transform to multiply with the original unbroken object’s worldTransform matrix. This will make the chunks match up with their correct positions relative to the original object.

Here’s the script:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

scene = own.scene

crash = cont.sensors['crash']

if crash.positive:

    inactive_obs = scene.objectsInactive
    chunks = [ob for ob in inactive_obs if ob.get("cell_part")]
    lV = own.getLinearVelocity()
    aV = own.getAngularVelocity()

    for chunk in chunks:
        pos = chunk.worldTransform.copy()
        offset = own.worldTransform.copy()        
        chunk_ob = scene.addObject(chunk,own,0)        
        chunk_ob.worldTransform = offset * pos
        chunk_ob.setLinearVelocity(lV)
        chunk_ob.setAngularVelocity(aV)
            
    own.endObject()    

setAngularVelocity doesn’t seem to work that well, maybe using apply impulse would be better…
Also getting the chunks to explode like in the first tutorial above will require more work.

You need to follow the above tutorial about the cell fracture plugin:


(not my tutorial, so please don’t ask me questions about that one :slight_smile: )

And here’s a demo blend file:

Thanks, this is a great tutorial and very easy to follow, I only have one question though, how do you parent all the individual pieces into a chunk below?

chunk_ob = scene.addObject(<b>chunk</b>,own,0)  

Chunks is a list of "chunk name"s, so the code is running once for every chunk in the list. The chunk you see in the addObject part is actually the “chunk name” from the list of chunks.

for example a bomb

@@Smoking_mirror, thanks for the explanation, I was confused between the chunk and chunks lol