0
\$\begingroup\$

I am currently making a tile based collision system. But I encountered a big problem I can't seem to figure out.

Use the image bellow for reference.

Gray lines represent the border between tiles. White square is void and grey square is a wall. Purple is a collision box and red lines represent the collision tested.

Fig 1. is the way I'm currently testing for collisions. I test for the tiles adjacent to the box.

Fig 2. is my problem. If the box slightly enters a tile in a corner, the collision will not be tested. I see you coming and tell me to test for diagonal collisions. See Fig3.

Fig 3. If I test for diagonal collisions, then if the box slides along a wall, it will hit the diagonal tile and completely stop (green line)

So I'm not really sure what to do at this point. I tried to look for 2D based tile collision detection and resolution, but nothing I found could solve my problem.

1

\$\endgroup\$
1
\$\begingroup\$

Well, I am pretty sure that the problem is in the anchor point, that you use to control the position of the collision box. To get the results you want, I would recommend considering the 4 corners as anchor points, simultaneously, just like a plane, so, in your code, the collision listener must be fired whenever any point between the corners touches the wall. You can consider the corners as A, B, C, D, and any point between them as a collision bound.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.