bevy_xpbd
                                
                                
                                
                                    bevy_xpbd copied to clipboard
                            
                            
                            
                        Make contacts deterministic across Worlds
Objective
- Fixes https://github.com/Jondolf/avian/issues/406
 
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
- A solution is to keep using the 
aabb.min.xto order the two entities. - There are a couple concerns:
- we want to make sure that when we match with previous entity pairs, this is not an issue.
- it's not a problem for 
previous_contactshere: https://github.com/cBournhonesque/avian/blob/ac1fd0269e04f19f6892c62019cbb9ad9c19444e/src/collision/narrow_phase.rs#L549 because we check both directions - it is a problem for 
match_manifoldshere: https://github.com/cBournhonesque/avian/blob/ac1fd0269e04f19f6892c62019cbb9ad9c19444e/src/collision/narrow_phase.rs#L571 which is why we modify the function 
 - it's not a problem for 
 - we want to make sure that this doesn't change how 
CollisionStartedandCollisionEndedevents are sent, even if the entities change their order during a contact. we should probably add a test for this- it should be fined because those events are based on the 
Contactsstruct that is generated during the narrow phase, and we made sure that contact matching still works independently of past entity order 
 - it should be fined because those events are based on the 
 
 - we want to make sure that when we match with previous entity pairs, this is not an issue.
 
Test
- tested in lightyear that the simulations are now completely deterministic
 - probably need to test that contact matching works correctly, even if the 
aabb.min.xof the two entities gets swapped during the contact