Search Unity

Disabling Speculative Contacts for less robust but more accurate collision detection?

Discussion in 'Physics for ECS' started by Mr-Mechanical, Nov 28, 2019.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    I am going to reuse Unity Physics's Collision detection for my own custom physics system, and I am slightly worried about the use of speculative contacts for my use case. They are cool and seem to be designed to help solve tunneling, however, I am concerned about ghost collisions. Would it be a bad idea to try to disable speculative contacts? In my use case, the convex hulls seem large enough that tunneling should be uncommon.

    Thank you for the insight, it is incredibly helpful.
     
  2. MaxAbernethy

    MaxAbernethy

    Joined:
    Mar 16, 2019
    Posts:
    53
    Without speculative contacts, bodies can penetrate or tunnel. For example, think about dropping a ball on the floor. With speculative contacts it should land precisely on the floor. Without them, it will have to penetrate the floor before the collision is detected, then it will be pushed back out of the floor over time. If the ball is falling fast enough, it might even just go through the floor completely without ever touching it. Those problems can be reduced by taking shorter steps, although that also reduces ghost collisions from speculative contacts.

    Another consideration is that penetration increases the cost of collision detection. When shapes are separated we only need GJK to find the closest points, but when they penetrate we need EPA, which is a lot slower.

    If you want to try disabling speculative contacts, I think it would work to have MotionVelocity.CalculateExpansion() return MotionExpansion.Zero.
     
    Mr-Mechanical likes this.
  3. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    Thanks for writing this. This is helpful. My use case is an object sliding on a static floor. So my current hypothesis is ghost collisions are too dangerous for my use case. Thank you.
     
  4. Andresmonte

    Andresmonte

    Joined:
    Nov 22, 2014
    Posts:
    37
    Hello, I want to know if this is related to a problem I'm facing.
    When I shoot bullets downwards to the ground instead of them to ricochet against the ground, they just get fired upwards to the sky.
     
  5. MaxAbernethy

    MaxAbernethy

    Joined:
    Mar 16, 2019
    Posts:
    53
    Hi tavovallejo, hard to say. Can you make a video that shows the problem? Normally when a body hits a flat surface, unless its restitution is greater than zero it should just slide along that surface.
     
  6. Andresmonte

    Andresmonte

    Joined:
    Nov 22, 2014
    Posts:
    37
  7. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    for very fast bullets like those you'd probably be better off handling them with raycasts/colliderCasts instead of with dynamic bodies

    Every frame, cast from previous position to current in order to detect hits
     
  8. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Totally agree on casting for fast bullets. If you do want to understand what is going on with your rigidbody bullet I'd suggest adding a Debug Display component and enabling the Collider, Broadphase and Contacts viewers upload_2019-12-9_12-19-33.png
    Then when you step the simulation one frame at the time you'll see where the collision as being detected and applied.