Search code examples
c++box2dcollision

Box2d stranglely does not detect collision


I have implemented b2ContactListener for detecting collisions. I have a world with gravity equal to (0,0) and I have a dynamic body which is not a sensor and Kinematic bodies which are sensors. The collision between them is not being registered strangely. But when I make the kinematic bodies non-sensors, then collision is being detected and dynamic body changes the position because of the collision. Could it be because I move both dynamic and kinematic bodes by using body->SetTransform(...) function? Or I am missing something else?


Solution

  • I have fixed the problem: I have changed sleeping setting to m_world.SetAllowSleeping(false); and it worked. The problem was the following: as far as there was a no physics simulation, and I have moved the object by calling SetTransform function the objects were sleeping. On the other hand sleeping objects cannot register collisions. Hence, when I didn't allow sleeping it started to call BeginContact callback.