Explosions

Is there anyway to make an explosion? I.e. apply force radially outwards from a point, decreasing with distance?
Quote:
Is there anyway to make an explosion? I.e. apply force radially outwards from a point, decreasing with distance?

I think just as you described, more or less.

If you're talking about having an object explode (e.g. an asteroid or something), I think the most logical approach would be to create multiple bodies (the fragments from the explosion) and assign to the fragments velocities with random magnitudes, directed outward from the origin of the explosion. (Or, apply an impulse to each fragment, all with the same magnitude, and let the speed of each fragment be determined by its mass properties.)

If you're talking about some sort of 'blast wave' effect that 'pushes' objects over time, then I would try the following:

For each update (as long as the explosion is active), perform a proximity query via Box2D to determine which objects are potentially affected. For those that are within the 'blast radius' (which could increase over time, if that's the effect you're after), apply a force with magnitude proportional to the distance from the object to the origin of the explosion, and directed outward from the origin of the explosion.
I never heard of a proximity query. I guess I'll have to look into it.
Quote:
I never heard of a proximity query. I guess I'll have to look into it.

Unless something's changed recently, for the current C++ version, the function you'll want to look at is b2World::QueryAABB().

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