Idea for implementing explosions

darkzerox, I think you arrived at the conclusion that I would have come up with if I had some more time to think about it.

I think your solution solves all of the problems that I've thought about.
Actually... crap. I think there *is* a problem with this. Large objects would still receive less force than they should, because the furthest points may receive little or no force at all, whereas a small object would receive forces along all its points.


I don't see where exactly the problem is because a large object should not recieve the full force of the explosion, only a part of it will, precisely because it's so big that only a part of it is within force-applying range.

For most purposes I'm thinking 10 rays per object is a little excessive especially if there's going to be lots of explosions in a game. But this method is definitely about as physically correct as you're going to get.
These two objects should receive the same amount of force applied to the part that's closest to the explosion, but instead, the larger object's rays are spread across its body, so that part receives less force compared to the other object.
darkzerox wrote:These two objects should receive the same amount of force applied to the part that's closest to the explosion, but instead, the larger object's rays are spread across its body, so that part receives less force compared to the other object.

Weight the impulse so that the same angular area gets the same impulse - this will automatically account for distance falloff, too (albeit in 2d rather than 3d).
ewjordan wrote:Weight the impulse so that the same angular area gets the same impulse - this will automatically account for distance falloff, too (albeit in 2d rather than 3d).
What do you mean? Weight it according to the area of triangles formed between the rays? That sounds like it would fix the problem, but I'm not sure how this helps with distance falloff.... the further parts would have larger areas, giving them more force, not less?
The accuracy of distribution of force would decrease on the block on the right, but if you assign the forces realistically it should still be fairly correct.

Basically you would apply a force for each ray that intersects with target shape, and the force is proportional (inverse, inverse square, or what have you) to BOTH the length of the ray and the total angle spread. So in that picture you made, the rays for the shape on the right will apply LARGER forces since that shape on the right covers more arc length. To get exactly identical forces applied to the left section you are drawing attention to, the 2nd shape should also get proportionally more rays to compensate (in which case the rays would then indeed carry the same force).

I hope you see what I'm getting at. I think this is what ewjordan said too.

I'll try to implement this as soon as i can...
Ohhh! If that's what ewjordan meant, then I misinterpreted him 🙂 That makes more sense.

You gonna do a flash demo dc443?
No I don't do flash. This is going into my C++/OpenGL project. I could probably make a demo or something at some point showcasing the features... later on...
That's about what I had in mind. One other thing to consider is the angle that the rays make with the face - this should be factored in to the impulse magnitude and direction (dot the unit ray with the negative unit normal to get the scaling factor and remember that explosive force should be in the negative normal direction).
ewjordan wrote:remember that explosive force should be in the negative normal direction


I actually completely forgot about this. This should make it even more realistic, though i can't help thinking that there should maybe be a little bit of "friction" force involved.
dc443 wrote:I actually completely forgot about this. This should make it even more realistic, though i can't help thinking that there should maybe be a little bit of "friction" force involved.

Absolutely - you can do this by weighted averaging the original default impulse (i.e. the direction of the ray and the usual magnitude at that distance, i.e. what you would apply if the ray was normal to the edge) with the one that's normal to the face, i.e.

newImpulse = (1.0f-frictionFactor) * normalImpulse + frictionFactor * originalImpulse;

where frictionFactor is small.

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