Jump to content

P2 - Detect side from a collision


lonelydatum
 Share

Recommended Posts

Someone like Wayfinder will probably be able to further elaborate on this but I believe that because P2 uses arbitrary polygons for collision, it has no concept of 'sides'. There are however many mathematical approaches such as dot/cross products to determine the relative angle between two colliding objects, as well as of course just using the difference of the x and/or y positions to determine if an object is to the left, right, up or down of another.

Link to comment
Share on other sites

The easiest way (although perhaps not the most reliable for outlier shapes with extreme measurements) would be to check the angle of the vector between the two centers of mass of the colliding shapes.

 

Looking for reliable data in the contact equations is sadly not a good way to deal with this specific problem - p2 is extremely optimized and will stop checking as soon as it is certain two bodies overlap (which can mean that when you hit a corner with some overlap, it will usually only return a contactEquation for one of the two points of collision), and in some cases will not detect a collision that is taking place (for example, when a "spike" goes through a rectangle without any of either body's vertices contained in the respective opponent's area). 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...