3
$\begingroup$

I have a python script that is supposed to run whenever one of the bad guys (cubes) in my game gets shot. I'm using a cubelike style of art work, and I want the bad cubes to explode into smaller cubes when it gets shot. I've tried using a python script to create multiple instances of a smaller cube in the same spot where the original cube was, so that the physics engine will shoot them apart as soon as the next physics step takes place. Unfortunately, this method of doing things is not working. It either shoots the cube off in a direction making a trail of cubes behind it, or it deletes itself and makes one small cube, (depending on whether I tell the bad cube to delete itself before or after it runs the script that creates the small cubes). I don't really care how it's done, but if I could get some suggestions on how to achieve this effect, that would be great!

$\endgroup$
3
$\begingroup$

I did this in a way that is not computationally expensive for physics with the "Bake to keyframe" option.

I make my basic set up in Blender Render. The eight cubes that will compose the fractured cube are all set to rigid body "active" objects. A plane is added below them, and set to rigid body "passive".

Next, I add the object that will force the cubes apart, it can be anything, a monkey, a cube, ect... ect... Place it at the junction between the cubes and make it passive like the ground plane.

Now, play the animation through to make sure you like it. Scaling the "exploder" object has great effect on how the cubes break apart.

Select all the cubes and SpacebarSearch + "bake to keyframes". Click it, then click "Okay" on the popup window.

Now all you need to do is make each cube play the animation(s) always in game, parent them all to another no-collision object, move to another layer, and have the original cube add the parent when it dies.

If you create more than one such animation and use a Random sensor you can have great looking, variable, computationally inexpensive exploding cubes for your game.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.