Search Unity

Speculative collisions even for almost static bodies?

Discussion in 'Physics for ECS' started by WildMaN, Nov 26, 2021.

  1. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    128
    I have a bunch of columns close to each other, but not intersecting. And I'm picking up way lot contacts than I'd expect. It looks exactly like speculative contacts, although my bodies aren't moving anywhere (but not static either). Red broadphase outlines kinda prove it.

    So far my workaround is ModifiableContactPoint.Distance > 0 check to get rid of those ghost contacts, but am I right those are the speculative ones and such workaround makes sense?

    upload_2021-11-27_1-2-37.png
     
  2. MaxAbernethy

    MaxAbernethy

    Joined:
    Mar 16, 2019
    Posts:
    53
    Hello, just guessing, but there is this member of Unity.Physics.CollisionWorld:

    Code (CSharp):
    1. // Contacts are always created between rigid bodies if they are closer than this distance threshold.
    2. public float CollisionTolerance => 0.1f; // todo - make this configurable?
    I think reducing that value would prevent the contacts from being created in the first place. But it should probably be at least a bit above zero to have stable collisions. Lowering it also will also make it easier for bodies to tunnel. A body can start the step at rest and then accelerate during the step because of a collision or constraint, and in that case you might want contact points from nearby objects.
     
    WildMaN likes this.
  3. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    128
    Looks like you nailed it. Although there is no setter to try it out and be 100% sure, it totally explains all the weird artefacts of my ModifiableContactPoint.Distance > 0 workaround and the visual bugs like premature collisions. Basically it means that a lot of contacts are created within 0.1f threshold and then immediately discarded by my system, and the workaround doesn't actually make sense. And those which aren't discarded actually happen at around 0.1f distance, which is the size of an object, leading to all the visual nonsense I've encountered.

    Would be awesome if Unity guys make a setter for this field.