It seems that not too many people know this technique, though it is very simple.

It should take up roughly the same amount of time as 2 circle checks.

Here is AABB.class

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public class AABB { protected Vector2Float pos, size; public AABB(Vector2Float pos, Vector2Float size) { this.pos = pos; this.size = size; } public static boolean collides(AABB a, AABB b) { if(Math.abs(a.pos.x - b.pos.x) < a.size.x + b.size.x) { if(Math.abs(a.pos.y - b.pos.y) < a.size.y + b.size.y) { return true; } } return false; } public static boolean inside(AABB a, Vector2Float b) { if(Math.abs(a.pos.x - b.x) < a.size.x) { if(Math.abs(a.pos.y - b.y) < a.size.y) { return true; } } return false; } } |

And if you don't have your own implementation or whatever, the simplest possible Vector2Float:

1 2 3 4
| public class Vector2Float { public float x, y; } |

The method

, checks whether 2 AABBs are colliding, and

, checks whether a point is inside an AABB.

What you must remember, is that unlike most AABB implementations, the

**pos** vector, is the

**centre** of the AABB, and the

**size** vector is

**half the actual size**.

Enjoy!

(And could someone do a performance test with this test vs the normal rectangle collision test?

)