This project has moved and is read-only. For the latest updates, please go here.

Fixture OnCollision canceled by returning false (FP3.1)

Nov 14, 2010 at 8:33 AM


Is there a recommended way for handling collision when the physics of the collision should not be computed?

My current problem is that ObjectA and ObjectB should collide and when they do, I'd like to "kill" them. Since they are killed by a collision, there is no utility in calculating the physics of the collision. Thus, in the collision handler delegate, I return false.

However, returning false from the collision handler method comes with a bad side-effect -- that is, let's say ObjectA's collision handler method is called first. It will do some logic in the handler to kill ObjectA and then return false. ObjectB's collision handler method does not seem to be called, however. This means ObjectB doesn't die.

How can you have the best of both worlds?

Thank you.

Nov 14, 2010 at 1:36 PM

There was an issue reported by inconsistency in OnCollision delegate and I changed it to a new strategy where the collision handler for fixtureB does not get called if the first handler was canceled. I might change this back depending on the impact this new behavior have.

The solution for you is to only subscribe to the OnCollision delegates you actually need and then make all the logic in there. You get both colliding Fixtures in the delegate method.

Nov 20, 2010 at 8:03 PM

Thanks for the explanation, Genbox.  How likely is it that you change back the behavior so both handlers are called in the case that false is returned from the first?

I'm going to change my code to work with this new behavior, but if it ever switches again, then more interesting stuff will happen and I'll have to revert back.


Nov 20, 2010 at 8:16 PM

I already changed it back. Too many users experienced problems with this new behavior.