Make contacts deterministic across Worlds #480
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
We noticed an issue where the Collisions were using the order of
Entity
directly to sort the pair of entities in a contact.The issue is that for networking, there is no guarantee that the pair of Entities that are replicated between a Client and a Server world are in the same direction.
Solution
aabb.min.x
to order the two entities.previous_contacts
here: /~https://github.com/cBournhonesque/avian/blob/ac1fd0269e04f19f6892c62019cbb9ad9c19444e/src/collision/narrow_phase.rs#L549 because we check both directionsmatch_manifolds
here: /~https://github.com/cBournhonesque/avian/blob/ac1fd0269e04f19f6892c62019cbb9ad9c19444e/src/collision/narrow_phase.rs#L571 which is why we modify the functionCollisionStarted
andCollisionEnded
events are sent, even if the entities change their order during a contact. we should probably add a test for thisContacts
struct that is generated during the narrow phase, and we made sure that contact matching still works independently of past entity orderTest
aabb.min.x
of the two entities gets swapped during the contact