Which two objects are colliding ?

Topics: Developer Forum
Jan 28, 2011 at 2:34 AM

Short question:

How can I determine which two specific GameObjects are colliding amidst so many different type of objects available in the game ?

Long question:

Usually, I have a CollisionMgr, which raises an event depending on which two type of objects collide. As I saw on the documentation, one can assign a delegate to a specific fixture and that method would be called. Now, I have two questions:

  • The delegate for both the objects would be called. I could in-turn call CollisionManager to resolve which two objects are in question and create an event accordingly. But, with this approach, for one collision two delegates will be invoked which would be resolved, resulting in two events being raised. This is something I definitely don't want! How can I get around this ?
  • Is there a way for me to determine which two specifc GameObjects are in collision ?

Thanks

Jan 28, 2011 at 5:39 AM

To prevent it being raised twice you could handle World.PostSolve/PreSolve or one of those. Box2D manual has more info on what each one does and some are better than others for certain things.

And set the Fixture/Body 's UserData property to the object it belongs to, to determine which is which. Are you doing this?

Jan 28, 2011 at 5:46 AM

I'll checkout World.pre/postSolve! Thanks.

I can set the userData to base class GameObject, but then to figure out which is which is turning out to be a nightmare :(