The best way to apply correct spin after an explosion?
The best way to apply correct spin after an explosion?
I have the explosion force setup and it works great! I used the sample as a base. I can't seem to figure out the best way to apply a correct angular impulse during an explosion. Any help would be awesome.
Re: The best way to apply correct spin after an explosion?
It depends on what you consider to be 'correct' 
Simulating a shock front through fluid simulation and using the pressures to compute the impulses would get you pretty close to 'correct', but that's not quite necessary. You may find that just adding a little arbitrary angular velocity looks fine:
(tiny unimportant note: this generates 'directions' pointing points within a cube; the samples will be biased towards the corners. Generating uniform spherical samples would be more 'random', but there may be no noticeable difference.)
A more expensive (and likely not-much-better) solution would be to send rays at each object, applying a portion of the explosion impulse with each ray. With a decent distribution and a sufficient number of rays, the response would be semirealistic. The number of rays needed to be noticeably better than a random angular velocity may be prohibitively expensive.
Other solutions that come to mind are sufficiently conceptually complicated as to cross into the realm of silliness. I'd suggest just trying out variants of the 'add a little angular momentum' strategy.

Simulating a shock front through fluid simulation and using the pressures to compute the impulses would get you pretty close to 'correct', but that's not quite necessary. You may find that just adding a little arbitrary angular velocity looks fine:
Code: Select all
entity.AngularMomentum += angularImpulse * new Vector3((float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1);
A more expensive (and likely not-much-better) solution would be to send rays at each object, applying a portion of the explosion impulse with each ray. With a decent distribution and a sufficient number of rays, the response would be semirealistic. The number of rays needed to be noticeably better than a random angular velocity may be prohibitively expensive.
Other solutions that come to mind are sufficiently conceptually complicated as to cross into the realm of silliness. I'd suggest just trying out variants of the 'add a little angular momentum' strategy.
Re: The best way to apply correct spin after an explosion?
Thank you Norbo, the simple approach worked beautifully.
Re: The best way to apply correct spin after an explosion?
I'm not sure if you can do it yet with BEPU, but what if instead of using rays, you'd use cones?
Small objects would be only affected by one or two cones, bigger, more noticeable, objects are hit by more cones.
Small objects would be only affected by one or two cones, bigger, more noticeable, objects are hit by more cones.
Re: The best way to apply correct spin after an explosion?
You could indeed query with cones (or frustum-like shapes), but they would not be 'traced'. Intersection points would be found by using traditional penetration tests. So, while fewer queries could be used without having to worry about 'missing' objects, the hit points would often have uninformative normals and deeply contained locations compared to ray tests. Angular impulses computed based on these tests would likely be no better perceptually than the simplest approach. Proper beam tracing would do much better but is not supported (and a suitable implementation would be very complex).