What is a hit box?

What exactly is a hit box? Is there any way that knowing about hit boxes could help in a game?


Solution 1:

Definition

A hitbox is an invisible box-like area that when penetrated, counts as a "hit". It's different than the model (the visible character and his colors that you see). The hitbox is meant to compensate for lag and movement. When a character is moving, his hitbox is usually farther from the model. When a character is still, his hitbox is located directly on top of his model.

Contrary to the name, a hitbox is actually composed of several boxes that represent the character's different areas (head, arm, torso).

Hitboxes, and You

You should definitely know how the hitbox affects you. It's the source of nearly all bizarre "WTF, how did I die?", and impossible shots that you see other players making. Understanding the hitbox is key to understanding how you die (and possibly getting better at your game).

Demonstration

A picture is worth a thousand words, so here's an excellent video from Team Fortress 2:

http://www.wegame.com/watch/TF2_Hitboxes/

Watch how the hitbox moves according to the model, where it moves and when, and lastly, understand where you need to shoot to penetrate that hitbox (and score).

Illustration

Below is a picture of hitboxes in Counter Strike. As these models are sitting still, the hitboxes are right on top of them.

Solution 2:

The main reason they use a hitbox for collision detection is that computing a hit based on geometry is increasingly expensive as the geometry gets more complicated. Typically there are actually multiple bounding boxes that are used. Partly, this is because a hit test against a rectangular box uses simple math and is very fast. If it misses the outermost box, they can shortcut the process and simply stop checking any further. A hit on the outermost box prompts a check for a closer box. However, they also don't want to recurse too far, or else it becomes too expensive (in time spent). At some point they must say, "that's close enough - it's a hit!"

One technique sometimes used for this is called an "octree", where 3D space is defined in terms of a recursive hierarchy of cubes. If two objects are in completely different branches of the octree, there is no possibility of them colliding so the detection can halt there. As they get closer to one another, the hit test becomes increasingly refined until the system knows that they have intersected or collided.

Solution 3:

A hit box is a region inside of which a character is placed.

It is an optimization used to speed up collision detection.

In a 3d shooter, for example, if you know what shape and size the hit boxes are, you could potentially aim for them, rather than the actual enemies. This could allow you to compensate for lag properly, or to get a head-shot when no part of the head is visible.

Here is an example:

Hitbox