Search Unity

Any ideas on how to resolve this sphere collision math?

Discussion in 'Physics' started by JamesThornton, Feb 13, 2020.

  1. JamesThornton

    JamesThornton

    Joined:
    Jun 26, 2015
    Posts:
    52
    I'm working on a billiards project.

    The balls are moved from their current position to a new position based on their velocities.

    Then Physics.OverlapSphere to test for overlap.

    Then I need to calculate where the positions would be at the moment of collision (P1 & P2) based on their velocities.

    Not quite sure how to calculate those positions, since the balls can be moving at different velocities and angles.

    Thanks for any tips!
     

    Attached Files:

  2. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
  3. JamesThornton

    JamesThornton

    Joined:
    Jun 26, 2015
    Posts:
    52
    The variance in speed is what makes it more complicated than basic intersection math. It's trivial to find the collision point if both balls are moving the same speed, or if one is still.

    But I'm sure that information will be helpful in solving this, so thanks for sharing! Going to study this today, see if any light bulbs go off.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    When thinking about stuff like this, it's easier if you try think of simpler tests or ways of reducing the complexity in a way that is equivalent. Often this comes in the form of taking something away from one and adding it to another, very much like the process you go through when rearranging an equation.

    So for instance, your concern about the two spheres moving at different velocities can be removed (reduced) to a problem of one sphere stationary and the other with its velocity as the relative velocity between the two.

    You can then reduce it further by removing the radius of one sphere so that it's a point and adding that radius onto the other sphere.

    The test then becomes a much simpler raycast across (v1 - v0) against a stationary sphere of increased radius (r1 + r2).

    This kind of manipulation is often used and can also be thought of making one thing simple by moving it into the space or domain of another before performing work. This can often make things faster but the only potential downside is that results may have to be inversed back into the original space/domain. In the case above, it wouldn't.
     
    JamesThornton likes this.
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    JamesThornton likes this.
  6. JamesThornton

    JamesThornton

    Joined:
    Jun 26, 2015
    Posts:
    52
    @MelvMay That makes sense! Very clever actually. That example is perfect. Back on this project today, and going to dig into this until I get it.

    Really appreciate your help!! I love the nuanced physics in pool. So the goal is to recreate that high fidelity precision. Researching it has actually improved my real game as well.
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    I highly recommend "Realtime Collision Detection - Christer Ericson (ISBN: 1-55860-732-3)" if you ever want a book that contains pretty much everything you'd ever need on this subject for both 2D and 3D.

    Anyway, good luck.
     
    JamesThornton likes this.