Inconsistencies between physic collisions and manual collision detections using CalculateDistance ?

Hi,
I encountered a case where a Unity.Physics.CollisionEvent is raised every frame, while PhysicsWorld.CalculateDistance(distanceInput, ref collector) does not return any hit.

To give a bit more context, I am currently playing with Rival, and I move my character (capsule collider) close to a cube and encounter an edge case. The character (kinematic) stop in place when coliding with the cube (expected behavior) and I stop moving the character at all.
At this point I have a ICollisionEventJob that triggers a collision between the character and the cube every frame. Nevertheless, inside Rival character controller, there is a a call to PhysicsWorld.CalculateDistance (with a max distance of 0) which returns only the collision with the character itself.
Increasing the max distance to something like 0.001 actually make PhysicsWorld.CalculateDistance return a second collision.

I would expect consistency between the two. Am I missing something ?

I can think of 2 reasons why a collision event is raised while a CalculateDistance(0f) returns nothing:

  • If the CalculateDistance() is called after the physics update (which is the case in Rival), and the “Synchronize Collision World” option is set to true in the PhysicsStep component, then we are calculating distance after the physics was solved. So, after the other collider got decollided from the character
  • I believe there is a certain collision tolerance value used by the physics solver to detect collision between shapes that are very close to each-other, although I’d have to double-check on that
1 Like

I would lean toward number 2 then, as with number 1, the built in collisionEvent would not continue to trigger on every next frames.
Good to know. Thx

https://discussions.unity.com/t/863475