Explode

Hello,

I am currently trying to use applyImpulse() to create a small explosion when I remove a block. basically I want to remove this block and everything around the block is moved slightly. I have tried messing around with the boxman demo script to see if I can get something working but I just don't seem to be able to get it.

so I want to apply a small impulse to everything around the block I am removing, any ideas will be much appreciated!

Thanks
I'm not quite sure how to do it. But I can give you a push in the right direction.

Mind you this is all typed right here and now and not tested, this may not work, and I'm to lazy to open flash and build a test environment.

Then push the selected bodies away like this:

Code:
//Params:
//theBody = The body to push away.
//centerPoint = The center point of the explosion.
//nRadius = The radius of the explosion.
//nForce = The force applied.
function pushBodyAway(theBody:MovieClip, centerPoint:Point, nRadius:Number, nForce:Number)
{
//Detect the direction as a V2.
var vectorToPushBody:V2 = new V2(theBody.x-centerPoint.x, theBody.y-centerPoint.y);
//Convert the V2 to a radian number (normalize)
var radDist:Number = vectorToPushBody.Normalize();
//Figure out how much force is needed (depending on how far away it is from the center of the explosion)
var hitForce:Number = ((nRadius-radDist) / nRadius)*nForce;
//Compile that back into a V2 to push the body.
var forceVector:V2= new V2(vectorToPushBody.x*hitForce, vectorToPushBody.y*hitForce);
//Actually move the body
theBody.ApplyImpulse(forceVector, theBody.GetWorldCenter());
}


Now I hope that's all right. :/

Original thread: https://box2d.org/forum/viewtopic.php?t=6914