Game Development Reference
In-Depth Information
Collision
Before we can make any more progress on the game, we need to look at the way collision works in
video games and the problems it can create for game programmers. Try and make sure you
understand the explanations that follow, because these issues are encountered again and again in
game programming and are common to both 2D and 3D games.
Problem 1: Just Passing Through
Games create the illusion of motion by drawing images at slightly different positions on the
screen over the course of time (much like a cartoon). In Game Maker, each of these positions is
called a step , where there are usually 30 steps in 1 second. This means that if Fishpod moves from
the top to the bottom of your screen in 1 second, then Game Maker will have redrawn its sprite in
30 different positions during its journey. This is called discrete time sampling , and it has a big
impact on collision detection. For when we add a collision event to Fishpod, Game Maker will
also perform a collision test in each of these positions to see if it has collided with anything
during that step. When an object moves slowly (as on the left of Figure 2-14), the position of the
bounding boxes overlap from one step to the next and so collisions are detected continuously.
However, when the sprite is moving much faster (Figure 2-14, right) it creates gaps between the
positions of bounding boxes in each step. A collision event is only called when two instances
overlap during a step, so it is now possible to create situations where Fishpod is above a platform
in one step but below it in the very next step. As a result, the collision event would never be called
and Fishpod would appear to pass straight through the platform. Worse still, if two instances are
travelling toward each other at speed (for example, a character and an enemy missile), then the
chances of them missing each other in this way is even higher. So one problem we must solve for
our platform game is to make sure that moving instances don't move so fast that they can pass
through each other.
Figure 2-14. Discrete time sampling produces gaps in collision detection when instances are moving very fast
 
Search WWH ::




Custom Search