erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
8.09k stars 1.52k forks source link

After calling SetTransform, it takes two Step() calls before overlapping bodies create a Contact #636

Closed agersant closed 4 years ago

agersant commented 4 years ago

Make sure these boxes are checked before submitting your issue - thank you!

This was originally discovered through the Love2D bindings (https://github.com/love2d/love/issues/1617). I have now reproduced this issue in Box 2D 2.4.0.

The issue is as follow:

  1. Create a world with no gravity and two dynamic circular objects, far apart from each other
  2. Step the world once
  3. Set the position of one of the two objects so that they now overlap
  4. Step the world once
  5. Observe that GetContactList() returns a contact (as expected), but BeginContact did not get called

If this is intended, I think it should be documented under https://box2d.org/documentation/md__d_1__git_hub_box2d_docs_dynamics.html#autotoc_md105 Note that calling Step() one additional time makes the BeginContact listener get called. However, I would expect it to be called during the time step where the contact is detected and not the following one.

I have attached an edited version of hello_world.cpp which reproduces the issue: hello_world.zip

Many thanks in advance.

agersant commented 4 years ago

Someone on Discord suggested calling IsTouching() on the contact in the ContactList. It was false after one call to Step, and true after a second call.

This means contact listeners and the contact list are consistent (🥳 ). However, it is still unexpected that it takes two calls to Step() before a contact is reported. (renamed this ticket accordingly)

erincatto commented 4 years ago

Fixed in #640

agersant commented 4 years ago

Thank you so much!