Page 1 of 1

manage collisions

Posted: Sat Aug 06, 2011 8:59 pm
by tinydev
hello, start using bepu and would like to know how an event is fired to be a collision between two objects, what happens is that I have my object a, object b, object c, object d, etc. and I need that when an object colliding with an object method is invoked

For Example: when object a hits object b invoked ab();
when object a hits object d invoked ad();
when object c hits object d invoked cd();

Re: manage collisions

Posted: Sat Aug 06, 2011 9:04 pm
by Norbo
Here's a general overview of the event system:
http://bepuphysics.codeplex.com/wikipag ... umentation

A simple demo that also includes events can be found in the Getting Started documentation:
http://bepuphysics.codeplex.com/wikipag ... umentation

It sounds like you want to do special things based on which objects are involved in a collision. The easiest way to do this is to put some logic into the event handler. You can check the two objects involved and possibly use a dictionary to look up an appropriate bit of logic to use for them.

There's no built-in support for filtering events specifically, though there is collision filtering through collision rules (http://bepuphysics.codeplex.com/wikipag ... umentation).

Re: manage collisions

Posted: Sun Aug 07, 2011 7:47 pm
by tinydev
ok thanks. tried and seems to work, I have only one doubt in my test drive the example of the page where the objects should disappear according to collide with deleterbox but that's so, why is this happening?


void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
{
var otherEntityInformation = other as EntityCollidable;
if (otherEntityInformation != null)
{
space.Remove(otherEntityInformation.Entity);
Components.Remove((EntityModel)otherEntityInformation.Entity.Tag);
}
}

Re: manage collisions

Posted: Sun Aug 07, 2011 8:40 pm
by Norbo
Sorry, I don't understand the question.

If you're just asking for general information about that part of the code, that is attached to a deferred event (collision event with a past tense name) that executes at the end of the frame. Since it is guaranteed to also execute sequentially, you can do things like remove entities from the space within the event handler. You cannot remove entities from an "immediate" handler (collision event with a present tense name), because it will corrupt the state of the engine and possibly cause race conditions. Removing the entity from the space stops it from undergoing any further physics calculations. Removing the entity's Tag, which contains a drawable game component, stops the entity from being drawn.