If you want to make a game addictive you are going to have to make sure the way objects
collide is very accurate. A game could be absolutely brilliant in all respects except
collision detection, and the end result is that the game is almost guaranteed to be
a complete failure. Likewise, the most simple game such as pingpong could still be
somewhat addictive if the collision detection is very accurate. I think that part of the
reason that the original DZone was popular was because the collision detection was done
at the pixel level. It was very much as case of what you see is what you get.
We will assume that we know how to take two 3D polygons and calculate whether they
cross over each other in 3D space. In theory we simple want to look at all polygons
in our scene and compare them with all other polygons to see if they intersect. If any
polygon collision is detected then the object that the polygon belongs to has it's
collision method called, which may destroy the object or cause it to stop, or whatever
is appropriate.
In practice this approach is far too slow. If there are 10,000 polygons involved
in the scene then there are 10,000 ^2 = 100 million polygon collision calculations to
perform.
The first thing to do that is fairly obvious, is to make sure polygons are not
checked with polygons that belong to the same object. In other words, only compare
polygons if they belong to different objects.
The second thing to do is to only compare polygons
across objects A and B if these objects are very close to each other. This produces
a radical decrease in the number of polygon collision checks that are involved, and the
process can be implemented reliably. When the model is loaded into memory for the
first time, a calculation is done for each vertex to determine the distance to the
object's center, and the longest distance is recorded as 'maximumRadius'. The
collision detection then begins by chosing only pairs of objects that have their
centers separated by less than the sum of the two maximumRadius values of each
object. In a typical scene involving objects floating around space, this means
that absolutely no polygon intersection calculations are generally performed. If
two objects become very close then the polygon intersection calculations begin.
I would be satisfied to end here, however if you have models that involve more
than a few thousand polygons then you can speed the collision detection process to
any further extent you wish by simply creating 'Ghost Models' for each model that
are as close as possible to the original model but involving much fewer polygons.
This could be anything from boxlike ghosts that give poor but extremely fast
collision detection, to almost identical copies of the model with minor detail
removed that doesn't relate at all to the model's shape.
With DZone v2.0 my philosphy is to favour code simplicity and gameplay
accuracy over speed optimization, so I'll probably skip the concept of Ghost
Models completely, but perform maximumRadius calculations. That way I am again
guaranteed that what you see is what you get and the project's production
time can be decreased.
Finally, all objects that are being rendered should be marked as either
SOLID or PASSABLE such that polygons that belong to a PASSABLE object are
excluded from your collision detection algorithm. Only large objects need to be marked
in this way because small objects will automatically be ignored owing to the maximumRadius
calcaulation. Examples of large objects that should be marked as PASSABLE include the
atmosphere for planets in a space simulator or clouds in a flight simulator, large
objects that you can look at through the window of a building, or the
background scene outside the playing field of a sports game. DZone v2.0 will
involve space stations on which the game is played, and the entire space station
can be marked as a single PASSABLE object.
This summarizes a simple and practical approach for dealing with collision detection
in 3D games and simulations. The approach works acceptably well for any sort of game
set in 3D space, from flight simulators to first person combat games to
sports simulations, and the method is intuitive and quite easy to implement.
