Getting forces applied to objects
Getting forces applied to objects
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
Re: Getting forces applied to objects
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.
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.
Re: Getting forces applied to objects
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?
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
Re: Getting forces applied to objects
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.