Game Development Reference
In-Depth Information
'
they aren
t simple shapes. Finally, a good collision system should support collision
groups because not every object needs to be able to collide with every other object.
A collision event should give you at a very minimum the following data: the two
objects that collided (or separated), the sum normal of the collision, and the force
of the collision. While it might not have occurred to you yet, objects separating are
equally as important in computer games as objects colliding. If two objects collide,
the game might impart damage to them or cause a sound effect to play. The force
of the collision might alter these events. You might want to run some kind of
particle-effect animation for forceful collisions, for example.
Some collision systems will give you more data, such as a list of contact points and
the collision normal for each of those points. This might be useful for spreading out
the particle effect or determining whether one object had sufficient force at one point
to penetrate the other object or cause some kind of special damage. I admit that last
example is a bit of a reach. I can
t think of any game that really goes that far just yet,
but someone might figure out a good use for this data.
Raycasting is both a savior and a curse. It stabs a ray from a start location in your
game world to any other point and gives you the collision information for anything it
intersects along the way. This is really useful for detecting line of sight from an AI
creature to your player
'
'
s character, or perhaps it can be used to probe the surround-
ing geometry to figure out where to place a third-person camera. The problem with
raycasting is that it
s only accurate to a point.
I know that was a horrible pun, but I
'
m actually serious. The ray is infinitely thin,
and it can therefore slip through the smallest cracks in your geometry. If you want
to know something about the general shape of the local geometry, such as if your
character is standing next to an open window, you can make a few stabs with these
rays, but they might miss something important, such as bars over the windows. Your
raycasts could instruct your character animation system to allow your player to climb
right through those bars.
I
'
s say you want to make a single raycast to deter-
mine if an AI creature can see your player. You could easily hide behind the thinnest
pole, if you were lucky enough to stand in exactly the right place. The ray could
intersect the pole, causing it to believe there was a solid object in the way. A simple
hack uses more raycasts from the center of the creature
'
ll give you one more example. Let
'
'
s forehead to various parts of
the player
s very difficult to hide, but those
raycasts are more performance intensive. Everything is a trade-off.
This can get expensive fast, though. Raycasts can be pretty expensive, especially if you
want a list of objects sorted by distance, rather than a simple yes or no answer to the
'
s body, like an arm or a foot. Then it
'
Search WWH ::




Custom Search