Game Development Reference
In-Depth Information
13 Collision detection
If you are simply creating animated demos then collision detection is
not an issue. But as soon as your characters are under user control
they can easily walk through walls. It is your job as the programmer to
stop this happening without interrupting the flow of the game. Collision
detection can be handled in very complex ways using particularly
heavy going mathematical approaches. In this chapter we are going to
look at some of the simpler ways of handling collisions. First, we will
look at a real world problem and some simple solutions to it using easy
to code bounding boxes. Next we will look at how basic bounding
boxes can introduce errors and how we can deal with these. Then we
will look at how many collision detection problems can be reduced from
a 3D to a 2D problem, greatly simplifying the code and speeding up the
implementation. If you are dealing with a fighting game then basic
bounding box collision detection with the two full figure fighting charac-
ters is not going to give enough information for your game logic; we will
look at how the full mesh can be handled in sections to get finer control
over collision detection. Finally, we will look at how to handle basic
collisions with the background. When a character is running near a
wall, it is better to align the character to run along the wall than to stop
the character when the angle of collision between the character and
the wall is very small.
A real world problem
To introduce the problems involved in collision detection, let's look at a
real world problem. Figure 13.1 shows a single mesh character running
down a tunnel. The scene character contains 994 polygons and the set
contains 529 polygons. The aim is to avoid the character running
through the walls. The most complex approach would be to get down to
the individual polygon level and calculate any intersections between
Search Nedrilad ::

Custom Search