Getting forces applied to objects

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
martin
Posts: 11
Joined: Fri Jan 13, 2012 3:30 pm
Location: Worcester, UK
Contact:

Getting forces applied to objects

Post by martin »

I want to attach some special behaviours to things when a force is applied to them, for example kill a player if a large force is applied to them or shatter some objects. I can't see any way to get an event when a force is applied in BEPU, am I missing something? Or if no such event exists, is there a simple workaround?
martindevans.appspot.com/blog
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Getting forces applied to objects

Post by Norbo »

There is no general 'force' measurement or event for an entity itself (beyond tracking its change in momentum over time, but this wouldn't catch an entity being crushed).

It is possible, however, to check the impulses applied by constraints associated with the entity. The Contacts list associated with each pair in the entity.CollisionInformation.Pairs list contains NormalImpulse and FrictionImpulse, among other data. The NormalImpulse could be used to determine if the entity was hit hard or getting crushed.

Other noncollision constraints also expose their accumulated impulse through the TotalImpulse property.
martin
Posts: 11
Joined: Fri Jan 13, 2012 3:30 pm
Location: Worcester, UK
Contact:

Re: Getting forces applied to objects

Post by martin »

Will either of those techniques pick up data from ApplyImpulse(impulse, direction) calls? If not, is there any good way to get that data?

Edit: Actually, I guess tracking changes to linearMomentum from one frame to the next would pick up those, and monitoring constraint pairs would catch everything else?
martindevans.appspot.com/blog
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Getting forces applied to objects

Post by Norbo »

The change of momentum over time is indeed the combined net force. Since it is the net force, if ApplyImpulse is called and shoves the entity up against a wall it was already touching such that it doesn't move, the net force contribution from the ApplyImpulse call will be zero because the wall cancelled it out with a force of its own. Checking for crushing or big impacts is a separate process which looks at the contact impulses.
Post Reply