InitialCollisionDetected fires more than CollisionEnded

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Abuzer
Posts: 20
Joined: Thu Jan 19, 2012 4:12 pm

InitialCollisionDetected fires more than CollisionEnded

Post by Abuzer »

Hi,

I've been trying to fix an issue I'm having in my project where I have a collision detection shape that (similar to the fish tank demo in BEPU demos) and I have registered event handlers with the InitialCollisionDetected and CollisionEnded events on a . My objects are CompoundCollidables that are also used as EntityCollidables. The collision object calling the event is the collision volume that is tagged as NoSolver and moves around with another Entity.

Basically I'm finding that for each time InitialCollisionDetected, I am not getting a corresponding CollisionEnded event call. I'm guessing there are multiple reasons as to why this might be happening. I even tried to move it with the EntityMover helper, instead of directly setting the position of the collision volume to equal the entity it's following, but no cigar.

BTW, I also saw this post from a while back, but unfortunately didn't help me much:

viewtopic.php?f=4&t=1262&p=7658&hilit=c ... ents#p7658

Any insight would be very much appreciated.

Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: InitialCollisionDetected fires more than CollisionEnded

Post by Norbo »

Relying on long-term perfect ordering and count when dealing with contact events can be dangerous, particularly when dealing with deferred events and compound bodies (and even moreso, compound body child events). Creating a bug-free usage in that context can get tediously complicated. Since there's so many things that can happen in so many different orders and places, my usual suggestion is to use a slightly more 'state-blind' approach.

For example, if a count is maintained for the purposes of determining if objects are currently in collision, it can be replaced by checking the entity.CollisionInformation.Pairs listing (or NarrowPhase.GetPair). Another option is to use one of the repeated events, like PairUpdated.
Post Reply