Page 1 of 1
addEventHook Help!
Posted: Thu May 07, 2009 10:12 am
by Fax3D
Hi all,
i'm trying to get a callback when two entities collide each other. I read the right way to do this is to use (Entity).addEventHook but i' can't make it works!
this is my code:
Code: Select all
....
m_PhysicsBody.addEventHook(new BEPUphysics.Events.EventHandlerControllerCreated(Event));
....
public void Event(Entity entity, BEPUphysics.Controller controller)
{
//Some logic here...
}
Where "m_PhysicsBody" is a CompoundBody with one ore more entity inside. So, when i make two m_PhysicsBody collide each other no events are fired!
What could be the problem?
Thanks for help!
Fax3D
Re: addEventHook Help!
Posted: Thu May 07, 2009 11:17 am
by Norbo
The collision-related events currently operate on the sub-bodies which are actually doing the colliding. If you listen to the compound body only, you'll miss the subbody reports. I think for the next version I'll send event notifications from the parents as well as the colliding children to make it easier.
Also, the EventHandlerControllerCreated event will fire when bodies come close to each other; for precise collision event throwing, you could use EventHandlerInitialCollisionDetected.
Re: addEventHook Help!
Posted: Thu May 07, 2009 2:40 pm
by Fax3D
Ok thanks for help Norbo!
Now doing like this:
Code: Select all
foreach (Entity entity in m_PhysicsBody.subBodies)
{
entity.addEventHook(new BEPUphysics.Events.EventHandlerCollisionEnded(Event));
}
Works very fine!
Fax3D
Re: addEventHook Help!
Posted: Sat May 09, 2009 3:26 pm
by b3n
I get now events for my subbodies when I do it exactly like the code above. I get events when I use just a single Entity, but as soon as en entity is a subbody, no events are generated anymore for that entity. Do I need to do anything else? I just create the subbodies, add them to a List, then create the CompoundBody with that list as argument for the constructor, then after that I'm doing the thing above. I never Update or do something with the subbodies. The subbodies are also not added to the space which should be ok?
--> Why I get no collision events for the subbodies?
Re: addEventHook Help!
Posted: Sat May 09, 2009 5:37 pm
by Norbo
If it isn't already, move your addEventHook statement after the compound body is added to the space. There's an inconsistency in how the add method deals with normal eventful entities and compound eventful entities that's fixed in the next version.
Re: addEventHook Help!
Posted: Sat May 09, 2009 7:28 pm
by b3n
Thanx, that worked.