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 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).
More settings
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
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 and , so the Pythagorean theorem finds it:
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
- The gap between centers is the long side of a right triangle (Pythagorean theorem)
d = \sqrt{-150^2 + 5^2} = 150.1\ \text{px} - Circles touch when the distance is less than the two radii added
150.1 \ge 90\ \Rightarrow\ \text{miss} - Games skip the square root to save time: compare the squares instead
22{,}530 \ge 8100
Export
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
| Symbol | Meaning | Unit |
|---|---|---|
| gaps between the centers | px | |
| hitbox radii | px |
- 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.
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.
Related exhibits
- Start here
Tuning a platformer jump: why some jumps feel floaty
Jump height is speed² ÷ 2 × gravity. Game designers tune those two numbers, and often make you fall faster than you rise, so the jump feels just right.
- Go further
Why fast bullets pass through walls: tunneling
Games move things in jumps, one per frame. If a bullet jumps farther than the wall is thick, it can skip right over it.
- Also try
Ladder against a wall: how high will it reach?
A ladder, a wall, and the ground make a right triangle. Pythagoras does the rest.
- Also try
Crosswind landing: splitting the wind into two parts
Pilots break the wind into “along the runway” and “across it.” That’s vector math at 60 knots.
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.