Setting contact.Enabled = false not having effect
jocamar opened this issue · comments
I'm trying to conditionally ignore a contact in my OnCollision callback but it doesn't seem to be working. Bodies still collide with each other. At first I though it might be a problem with my code but after I replaces my callback with just "contact.Enabled = false;" and bodies were still colliding with eachother I think there may be a bug with the physics engine.
Am I doing something wrong? Shouldn't it be possible to cancel a contact? In Farseer you used to be able to return false in the callback to achieve this behavior.
If you are calling the event from multiple places and setting the contact.Enabled = true
again, then it might be the problem.
At the moment I'm only setting the contact.Enabled to false. In fact that's the only thing my OnCollision
callback does in order to simplify the issue. My OnBeforeCollision
callback just returns true and my OnSeparation
callback does not change the contact.
https://github.com/jocamar/Caravel/blob/master/Source/Core/Physics/Cv_VelcroPhysics.cs
In here basically I replaced the OnNewCollisionPair body with just contact.Enabled = false
and bodies still collide.
I ended up adding an implementation of Aether Physics (https://github.com/tainicom/Aether.Physics2D) which has a pretty similar base and API and now I can instantiate both physics engines at my choice. The Aether implementation works as intended by returning false in the OnCollision handler, the Velcro one has the problem mentioned above.
In an attempt to make sure users only get OnCollision and OnSeparation called once, I implemented a bug where contacts are enabled on each world step, but OnCollision is never called again to re-disable it. It requires a bit more thought it seems.