This project is read-only.

ContactListener bug?

Jun 13, 2010 at 5:52 PM
Edited Jun 13, 2010 at 7:54 PM

I have a problem with ContactListener. Why ContactListener call BeginContact ... EndContact when first object hit AABB of other object ?

I have a bullets in my game. When bullet hit wall , I destroy the bullet in ContactListener and create sparks (for fun). But, when wall b2Body have angle PI / 2 (for example) , bullet destroyed when hit AABB of wall , I do destroy process In PreSolve function of ContactListener

How can I solve my problem ?


Demonstation of problem:

BLUE RECT is AABB of wall
ORANGE RECT is wall body
Circle is a bullet
Orange lines is sparks =)


b2Body Rotation is  0f , all works fine (because AABB the same as body vertices)

 But, when I rotate body, bullet begin tobe destroyes when hit AABB of wall

Jun 14, 2010 at 12:27 PM
Edited Jun 14, 2010 at 12:28 PM

That's not a bug, that's how contact listener is designed to work. It tracks objects that are likely to collide. In PreSolve, check contact.IsTouching to see if the objects are actually colliding right now.


It's also probably a good idea to not destroy them in PreSolve. Keep a list of bodies to destroy, and destroy them after the update is finished.