addEventHook Help!

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Fax3D
Posts: 22
Joined: Mon Sep 29, 2008 7:42 am

addEventHook Help!

Post 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
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: addEventHook Help!

Post 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.
Fax3D
Posts: 22
Joined: Mon Sep 29, 2008 7:42 am

Re: addEventHook Help!

Post 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
b3n
Posts: 3
Joined: Mon May 04, 2009 5:43 pm

Re: addEventHook Help!

Post 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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: addEventHook Help!

Post 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.
b3n
Posts: 3
Joined: Mon May 04, 2009 5:43 pm

Re: addEventHook Help!

Post by b3n »

Thanx, that worked.
Post Reply