I'm trying to figure out what my options are for implementing explosions in my game (which of course uses Box2D). Presently I'm relatively clueless... I'm not concerned with the graphics-side, mind you, I'm concerned with the physics-side.
Explosions
General DiscussionI don't know of any built-in methods for explosions, so what I would do is apply a force to every body, keeping in mind that the intensity of the explosion is inversely proportional to the square of the distance.
It would be something along the lines of this:
F_applied = F_total / r^2
Note that this wouldn't take into account the surface area of the body that is being hit with the force, but that is roughly proportional to the surface area for convex shapes, so the surface area could be a factor when calculating the applied force.
If the explosion lasts multiple physics steps the force would need to be re-applied for every step.
It would be something along the lines of this:
F_applied = F_total / r^2
Note that this wouldn't take into account the surface area of the body that is being hit with the force, but that is roughly proportional to the surface area for convex shapes, so the surface area could be a factor when calculating the applied force.
If the explosion lasts multiple physics steps the force would need to be re-applied for every step.
Original thread: https://box2d.org/forum/viewtopic.php?t=958