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)1

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

SymbolMeaning
axA: x
ayA: y
awA: width
ahA: height
bxB: x
byB: y
bwB: width
bhB: height
hitHit (1 = yes, 0 = no)

More formulas in this category

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