0
\$\begingroup\$

I've implemented some collision detection using separating axis theorem. Works fine for axis-aligned rectangles and two out of four possible right triangle orientations. For some reason when the hypotenuse is oriented down left or up right, the minimum translation vector being calculated is that of the normal of the base or height of the triangle rather than the hypotenuse that is being collided with.

https://i.sstatic.net/W5WHH.png

I've got a jsfiddle demo of my implementation. The center box and right side triangles all show a correct MVT when the collision box collides with them. The ones on the left side do not. Move your mouse over the canvas to move the collision box.

http://jsfiddle.net/XLtdB/

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This is a problem somewhere in your code. You need to debug your code. Try writing out the algorithm on paper with pictures and see if your code follows the algorithm correctly. Overall I think this question is too localized since it's just your code that's the problem. \$\endgroup\$
    – House
    Commented Jan 1, 2013 at 16:32
  • \$\begingroup\$ You are making an undue assumption about which direction to move in checkNormal. \$\endgroup\$ Commented Jan 1, 2013 at 23:17

1 Answer 1

1
\$\begingroup\$

I know this is a very old question, but for those trying to use this code to make a collision engine (like me), I will present a solution, though not a very elegant one:

For a reason I haven't yet identified, flipping the hypotenuse normal of the 'broken' triangles corrects the collision resolution.

Hope this helps:)

\$\endgroup\$
2
  • \$\begingroup\$ I think in your answer is something broken, right after the colon ;( \$\endgroup\$
    – yckart
    Commented Jan 11, 2016 at 18:47
  • \$\begingroup\$ No, nothing is broken, i just phrased my answer somewhat poorly when i wrote it :) \$\endgroup\$
    – Nikolai97
    Commented Jan 11, 2016 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .