Can I prevent collision events firing using collision rules?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Can I prevent collision events firing using collision rules?

Post by Spankenstein »

If I set up a CollisionRule:

Code: Select all

            CollisionRules.CollisionGroupRules.Add(
                new CollisionGroupPair(
                    collisionGroups[EntityGroup.Enemy], 
                    collisionGroups[EntityGroup.Harmless]
                    ), 
                CollisionRule.NoBroadPhase
                );
then the InitialCollisionDetected event still fires:

Code: Select all

        private void Events_InitialCollisionDetected(EntityCollidable info, BroadPhaseEntry entry, INarrowPhasePair pair)
when the objects from the two different collision groups come into contact.

Is there any way to prevent this without filtering out the groups in the event method itself? Or, what would be your recommended method for this scenario?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Can I prevent collision events firing using collision ru

Post by Norbo »

when the objects from the two different collision groups come into contact.
If the collision rules are set up and working properly, there will be no events. NoBroadPhase means that the pair never even exists, so there shouldn't be anything to trigger collision events.

Collision group rules are overridden by specific relationships and personal collision rules, though. You could check the CollisionRules properties of the collidables and INarrowPhasePair in the event handler to see if they are what you expect.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Can I prevent collision events firing using collision ru

Post by Spankenstein »

How about this scenario:

I would like the two objects to react to each other physically but I do not wish to fire off an event?

In other words two shapes overlap and are repositioned according to the contacts generated but I don't want to fire off an 'InitialCollisionDetected' event when this occurs. Is this not possible with 'CollisionGroups'?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Can I prevent collision events firing using collision ru

Post by Norbo »

The collision rules system is designed to stop stages of processing, not events in particular, so no.

CollidablePairHandlers do have an event suppression system; you'd have to set it using an event, so you don't gain much. Doing a little extra logic here and there may be the best option.
Post Reply