The best way to apply correct spin after an explosion?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
nizgtr
Posts: 6
Joined: Mon May 30, 2011 2:44 am

The best way to apply correct spin after an explosion?

Post by nizgtr »

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.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: The best way to apply correct spin after an explosion?

Post by Norbo »

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:

Code: Select all

entity.AngularMomentum += angularImpulse * new Vector3((float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1);
(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.
nizgtr
Posts: 6
Joined: Mon May 30, 2011 2:44 am

Re: The best way to apply correct spin after an explosion?

Post by nizgtr »

Thank you Norbo, the simple approach worked beautifully.
stino
Posts: 24
Joined: Sun Apr 14, 2013 9:05 am

Re: The best way to apply correct spin after an explosion?

Post by stino »

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.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: The best way to apply correct spin after an explosion?

Post by Norbo »

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).
Post Reply