Collision Basics

Collision detection is really more than just detection. We break down collisions into three areas of interest:

In summary, a game should try for these collision-detection goals:

The last goal is basically saying you don't want to restrict the player's movement too much during the course of a game. For example, you don't want to completely stop a player during a wall collision. Instead, let the player slide against the wall or gently bump off it. Also, you don't want your collision detection to be inaccurate to the point that the player can cheat by squeezing through the wall at certain locations in the map, for example. Let's start with a simple collision-detection algorithm. Consider that everything that moves in the game is an object, whether it's a monster, the player, a projectile, or whatever. For each object, follow these steps:

  1. Update the object's location.
  2. Check for any collisions with other objects or with the environment.
  3. If a collision is found, revert the object to its previous location.

Notice that you check for a collision after each object moves. Alternatively, you could just move all the objects first and then check collisions afterward. However, you'd have to store the object's previous location with the object, and problems could occur if three or more objects collide. Also, this basic algorithm just reverts an object to its previous location if a collision occurred. Normally, you want to use other types of collision handling based on the type of collision. With this algorithm in mind, let's get started with object-to-object collisions.