Page 1 of 1

making a Trigger (Enter/leave events)

Posted: Sun Mar 04, 2012 2:09 am
by fredlllll
Yeah i want to make something like a Trigger. so if an Entity enters my trigger(its a box) i want to raise my event. problem is i dont know how to make a box which does not affect my entities. but tells me when a entity starts to be partially in it or leaves it. (entity can be bigger than the box)

Re: making a Trigger (Enter/leave events)

Posted: Sun Mar 04, 2012 2:20 am
by Norbo
problem is i dont know how to make a box which does not affect my entities.
One option is collision rules. An example can be found in the CollisionFilteringDemo in the BEPUphysicsDemos. They can be used to disable various stages of collision detection and response between certain pairs or categories of objects.

Once you have that, then you can use the collision events to determine when objects come into collision or exit collision. Another option which might be easier to maintain in the case of a particularly complicated entity type is to just check the entity.CollisionInformation.Pairs list. Each Pair has a Contacts list. If the contacts list has at least one contact with nonnegative penetration depth, then you can be sure that the objects are currently colliding.

Another option is the DetectorVolume; it's similar to the above, but is a dedicated mesh-based detector volume. An example can be found in the BEPUphysicsDemos DetectorVolumeDemo.