Rectangle Collision (AABB)
Checks whether two unrotated rectangles overlap with four comparisons.
A.x < B.x + B.w and B.x < A.x + A.w and A.y < B.y + B.h and B.y < A.y + A.h
Axis-aligned bounding boxes collide when they overlap on both the x and the y axis.
They do not fit rotated or detailed shapes, so games often test AABBs first and check only the hits more precisely.
Calculator
Change a value and the result and picture update instantly.
Result
Hit (1 = yes, 0 = no)
Animated picture
The picture follows your values. Some points and shapes can be dragged.
Use in game development
The basic collision test for platforms, enemies and pickups in 2D games. Drag the blue box in the picture.
Code example (JavaScript)
const hit = a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
What the symbols mean
| Symbol | Meaning |
|---|---|
ax | A: x |
ay | A: y |
aw | A: width |
ah | A: height |
bx | B: x |
by | B: y |
bw | B: width |
bh | B: height |
hit | Hit (1 = yes, 0 = no) |
More formulas in this category
- Circle Collision
- Linear Interpolation (lerp)
- Easing Functions
- Cubic Bézier Curves
- Projectile Path
- Reflection Vector
- Pseudo-Random Numbers (xorshift)
Frequently asked questions
- What is the formula for Rectangle Collision (AABB)?
- The formula for Rectangle Collision (AABB) is A.x < B.x + B.w and B.x < A.x + A.w and A.y < B.y + B.h and B.y < A.y + A.h. Checks whether two unrotated rectangles overlap with four comparisons.
Math Formula Quiz Math for Game Development
Sources
Checked: 2026-11-29