Premature collision in Unity Physics

When colliding an entity created with a rigidbody and box collider with a static mesh collider entity at 100m/s, the actual collision seems to be detected prematurely, before the colliders intersect.

To illustrate the issue, I will compare Unity Physics (ECS) 1.2.4 with standard PhysX Physics.

  • collision locations are displayed as red dots and collision normals are displayed in cyan
  • both engines are set to run at 60Hz for comparability
  • collision detection mode is discrete

Unity Physics:

PhysX:

Question:
Is there a way to configure Unity Physics to detect collisions at collider intersection and not before? The current behavior causes some unwanted issues.

PhysicsStep.CollisionTolerance

1 Like

Thanks. This PhysicsStep field seems to be available from Unity Physics 1.3.0+ (currently pre-release).

The collision tolerance specifies the minimum distance required for contacts between rigid bodies to be created.

The default value of CollisionTolerance is 0.01. Setting this to a negative value i.e. -0.1 resolves the issue but leads to the object not coming to rest on the ground for example. If set to a larger value than the default, the problem becomes more prominent which is to be expected.

Am I missing something here?

The contact is generated before a collision occurs for continuous collision detection modeling to prevent tunneling. The contact tolerance configures how far away contacts will be created from the surface for this purpose.

If you see the contact, that doesn’t mean there is any force applied. If the object would not actually hit the contact surface, despite the contact being created, it won’t add any force to the rigid body.

They fact that you can set a negative contact tolerance is actually a mistake. It should not be lower than zero.

@daniel-holz

It is true, that not every contact results in an applied force, but I was not monitoring contacts but rather collision events.

To clarify, I have a cube with a damped spring underneath it. The impulse of this damped spring is applied betweenPhysicsInitializeGroup and PhysicsSimulationGroup via PhysicsWorld.applyImpulse(). This results in the following behavior:

premature-collision-sprung-cube

The first collision event is fired when there should not not be any overlap.

Am I applying the impulse at the wrong ‘moment’ here? If not, is there any configuration or workaround I can use here?

The first collision event is fired when there should not not be any overlap.

That’s just the nature of Continuous Speculative CCD.

There is Physics.ContactModifyEvent that allows you to ignore certain collisions, but its a bit challenging since it doesn’t run on the main thread (can’t use Unity API)

1 Like

Thanks @Lexone for pointing me in the right direction.

Unity Physics seems to employ speculative CCD as the issue I am seeing in my example is described in the Unity manual as an Issue of speculative CCD:

What I did to resolve the issue in my context was to create a IContactsJob (according to Overriding intermediate simulation results | Unity Physics | 1.3.8) and ignoring certain contacts via JacobianFlags.Disabled. Not sure, if this is the correct way to go, but it seems to work.

1 Like