Detecting and measuring impact force

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
mcmonkey
Posts: 92
Joined: Fri Apr 17, 2015 11:42 pm

Detecting and measuring impact force

Post by mcmonkey »

Through simple usage of BEPU's proper feature set, we can do this:

Code: Select all

            Body.CollisionInformation.Events.ContactCreated += Events_ContactCreated;
        void Events_ContactCreated(EntityCollidable sender, Collidable other, CollidablePairHandler pair, ContactData contact)
{
...
}
and in that event code, we can detect and react to the fact that an impact occurred.

However, there is no "proper" method to determine impact force!

What I mean by "impact force" is: How much force (mass*velocity more or less) is being applied to each object at the moment of impact. In theory, they each have an equal force applied in opposite directions (more or less).

I need no more information that a scalar value indicating a strength of impact, though directions would be surely be beneficial to other use cases.

So... what's the best way to go about determining the force / other relevant data involved?

Deeper into the system, there are variables such as "accumulatedImpulse" and "relativeVelocity" that may be relevant.

My current detection code uses complicated bad-quality access to these lower-level variables as a workaround to temporarily handle the situation until a better solution is available.


As always, thanks for the amazing work!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Detecting and measuring impact force

Post by Norbo »

The contact-providing events are created before solving takes place, so they do not know the impulse computed by the solver.

Deferred events which fire at the end of the frame (after solving) can go back and look it up. It's not done automatically, but it can be found easily using the passed-in CollidablePairHandler. Each contact in the CollidablePairHandler.Contacts collection includes a NormalImpulse property.

(Note: a common thing to do is to use the relative velocity on impact as a proxy for impact force or as an additional filter. If you do this, be careful! The relative velocity in the contacts collection is the post-solve relative velocity. The solver will have already applied anti-penetration and friction impulses. Getting around this requires caching previous velocities, and is a bit annoying.)
Post Reply