3
\$\begingroup\$

I realize there have been a multitude of questions involving 2D AABB vs AABB collision, but the questions and responses always avoid the simple questions that make it difficult.

To keep things simple, we are going to assuming that AABB1 is a moving(vector velocity and direction known) rectangle that is much taller than it is wide, and AABB2 cannot move and is a smaller square. If AABB1 were to move towards AABB2 from any angle how would you figure out which side of AABB2 it collided with?

Further, when calculating collision depth, I mean the distance it travels into the object on the x-axis and the y-axis. When finding those distances, how would you find what point would you use as reference? From what I can tell, you couldn't just use one point for every collision because with AABB1 (it is much taller than wide), the top left point would be irrelevant when finding the penetration depth on a collision with the bottom right corner.

Another but less important question than the other two, how can you handle an object with a velocity vector with a high enough magnitude to move through an entire wall in one frame. Say a wall is 50 pixels wide and a player is moving 100 pixels per frame, it could jump through the wall without triggering a collision.

If further information is needed to help solve my problems or understand the problem, please ask. I haven't found any post that helps and I don't have enough reputation to post pictures to elaborate in more detail.

\$\endgroup\$
3
  • \$\begingroup\$ I think this post will answer most of your questions: gamedev.stackexchange.com/a/55991/5864 \$\endgroup\$ Commented Dec 24, 2014 at 10:13
  • \$\begingroup\$ Nope, that only helped on the final question, not the more important first two. \$\endgroup\$ Commented Dec 24, 2014 at 18:39
  • \$\begingroup\$ The answer to the first question can be found here: gamedev.stackexchange.com/a/24091/5864 again using Minkowski sums. I’m afraid I don’t really understand your second question, since the collision depth does not really depend on the shape of the objects. Maybe a drawing would help clarifying. \$\endgroup\$ Commented Dec 24, 2014 at 23:43

1 Answer 1

2
\$\begingroup\$

I think in this situation you should add the extents of the moving AABB1 to that of the static AABB2 and then perform a Segment<>AABB test. In this case the segment starts at the position of the moving AABB1 and ends at position of AABB1 plus its velocity.

The result of the Segment<>AABB test will give you normal, thus the side. Assuming the segment intersects the AABB, you can then calculate the penetration, if needed, or just the actual 'just touching' position of AABB1.

This test works for any aspect ratio AABB, at any velocity.

I think the best example I saw of this was here: http://noonat.github.io/intersect/

\$\endgroup\$

You must log in to answer this question.

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