How does a video game know when something hits you?

Games wrap characters in invisible shapes called hitboxes, usually circles or boxes. For circles, the game measures the distance between the two centers with the Pythagorean theorem. If that distance is less than the two radii added together, the shapes overlap, and it counts as a hit. Boxes just check overlap sideways and up and down.

Distance 150 px vs. reach 90 pxΔx 150Δy 5dashed: the hitboxes · orange line: the distance (the long side of a right triangle)
Distance between centers
150 px
Hit if closer than
90 px
Gap (negative means overlapping)
60.1 px

Challenge: Line up two circles so they're touching but not overlapping (within 1 pixel).

px
px
More settings
px
px

Play

Press "Run it: charge in" and watch the moment the hitboxes touch. Then try the corner case with boxes.

Challenge: Line up two circles so they're touching but not overlapping (within 1 pixel). The box under the picture turns green when you get it.

Stuck? Pick one of the examples from the “Try an example” menu, or press “New example.”

Understand

Δx2+Δy2<rA+rB\sqrt{\Delta x^2 + \Delta y^2} < r_A + r_B

Two circles touch when the distance between their centers is less than their radii added together. That distance is the long side of a right triangle with legs Δx\Delta x and Δy\Delta y, so the Pythagorean theorem finds it:

d=Δx2+Δy2d = \sqrt{\Delta x^2 + \Delta y^2}

The blue legs and the orange hypotenuse show that triangle. Boxes that line up with the screen are even simpler: they overlap only if they overlap sideways and up and down. Press "Run it: charge in" to watch the moment of contact.

Use

Every input has a unit menu, so you can type values in the units you already have. Results follow your units.

Show the work

  1. The gap between centers is the long side of a right triangle (Pythagorean theorem)d = \sqrt{-150^2 + 5^2} = 150.1\ \text{px}
  2. Circles touch when the distance is less than the two radii added150.1 \ge 90\ \Rightarrow\ \text{miss}
  3. Games skip the square root to save time: compare the squares instead22{,}530 \ge 8100

Export

Export PDF

Pick circles or boxes and move the gap between centers. "More settings" resizes each hitbox.

  • Real games also use rotated boxes, capsules, and character-shaped meshes. They're all built from checks like these.

For learning and estimation. Verify with applicable codes, standards, and a qualified professional before using in design, construction, or safety-critical work.

Cheat card

d=Δx2+Δy2d = \sqrt{\Delta x^2 + \Delta y^2}
hit if d<rA+rB\text{hit if } d < r_A + r_B
faster: Δx2+Δy2<(rA+rB)2\text{faster: } \Delta x^2 + \Delta y^2 < (r_A + r_B)^2
SymbolMeaningUnit
Δx,Δy\Delta x, \Delta ygaps between the centerspx
rA,rBr_A, r_Bhitbox radiipx
  • The distance is the long side of a right triangle, so 3-4-5 triangles make easy numbers to check.
  • Games skip the square root and compare squares instead. It gives the same answer and runs faster.
  • Hitboxes are often bigger or smaller than the character on purpose, to make the game feel fair.

Print this card

Where it’s used

  • Computer Science
    Every action game checks hundreds of hitboxes many times a second.
  • Computer Science
    Robots and self-driving cars use the same distance checks to avoid bumping into things.
  • Hobbies & Crafts
    Fighting-game players study hitbox sizes to know exactly which attacks can reach.

Questions people ask

What is a hitbox?

An invisible shape around a character or attack that the game uses to check for contact. It's much simpler to check than the actual drawing.

Why did that attack hit me when it looked like it missed?

The hitbox may be bigger than the picture, or shaped differently. Boxes reach farther at the corners than circles do.

Why use circles instead of boxes?

Circles match round things better and are just as quick to check. Boxes fit walls, platforms, and screen-aligned shapes.

Updated : First published.

See everything that’s new on Maps for Math