Search Unity

Speculative contacts... Is it like continuous collision detection? How do they work?

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

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    I am trying to understand the collision scheme of Unity Physics, how do speculative contacts work? I notice that the bounding box grows to encompass its future position, but how does this also influence narrowphase? What is the purpose of it, does it make collision detection more robust (like ccd?). My understanding of this speculative system is incomplete. Can someone help clarify my understanding? Thanks a lot, I'm very intrigued about how this works.
     
  2. MaxAbernethy

    MaxAbernethy

    Joined:
    Mar 16, 2019
    Posts:
    53
    Hi,

    Speculative contacts means that we find the closest points/features on the bodies at the beginning of the step and use those to make contact constraints. It's not totally accurate because the bodies might not actually collide at those points, so sometimes collisions will occur when they shouldn't or bodies will penetrate. But it's often a good enough guess, it mostly solves the "bullet through paper" problem, and it's much faster than exact continuous collision detection.

    To generate speculative contacts we have to expand the body's AABB to include everything that the body might collide with. We can't know for sure what the body will collide with, so we just make a guess based on its current velocity. If the velocity changes during the step, for example if the body gets acceleated by a collision, then the guess will be wrong and the body might tunnel through something.

    Both of these systems can be inaccurate, but you can always improve the accuracy by taking shorter steps. Hope that helps explain it.
     
    Mr-Mechanical likes this.
  3. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    Thank you greatly for your detailed response. This helps my understanding. So I take it that there is an antipenetration/collision-constraint created if the expanded AABBs intersect, even if the convex hulls corresponding to those AABBs don't yet intersect (is this correct?). Thank you for the help so far, I am attempting to understand the specifics of the collision scheme implemented in Unity Physics as I am attempting to reuse the collision system for my own ECS physics engine.
     
  4. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    480
    Yes. This is talking about physics with GameObjects rather than DOTS but see the Speculative CCD section here https://docs.unity3d.com/Manual/ContinuousCollisionDetection.html
    I also discuss things here:
     
    Mr-Mechanical likes this.
  5. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    Great talk. Manual also helps answer my understanding of speculative contacts CCD. So based on my understanding of speculative contacts so far suggestion from another thread "If you want to try disabling speculative contacts, I think it would work to have MotionVelocity.CalculateExpansion() return MotionExpansion.Zero." would be the best way of disabling CDD (just removing AABB expansion should be the only difference)? I would like to experiment with it on it off for my use case. Thanks a lot.
     
unityunity