Game Development Reference
In-Depth Information
a good trick
is to cache the results of multiple raycasts over many game loops. If you cast one ray
per loop from an AI character, and your game is running at 30Hz, that
did my ray hit anything
question. Back to the line-of-sight question
s 30 rays per
second you can cast! Since human beings can only perceive delays lasting longer than
about 100ms, or 1/10 th of a second
'
you can even spread these
raycasts out farther to once every other frame or perhaps more. This is a game tuning
thing, and you
a good general rule
ll just have to play with it.
Another option is the shapecast. Think of this as pushing a geometrical shape from a
start location in your game world along a straight line to somewhere else. This is
more expensive than a single raycast, but it can be much more accurate if you are
moving an object in your game and want it to follow geometry closely. A good exam-
ple of this is a wall-following scheme, where your character closely follows the geom-
etry of a wall, including beams and wall sconces. Once you ' ve validated the move
direction, move the character away from the wall a bit and shape cast it back into
the wall. If something like a beam or sconce is in the way, the new position of your
character will accommodate the annoying geometry. This is exactly how the wall-
flattening algorithm worked in Thief: Deadly Shadows.
Phantom objects, or triggers, are usually pretty simple to code without a physics or
collision system. They are usually simple proximity alarms that fire when some
dynamic object gets within range or leaves the active area. You use these things to
open automatic doors, or perhaps fire poison darts, or something like that. If you
have a physics system, however, you can make these areas into any arbitrary shape,
as long as it is convex. This can be really useful for tuning triggers into tight areas in
your level. If all your trigger shapes have to be spheres or cubes, you ' d have to make
enough room for them to stay out of other rooms or hallways nearby.
The idea behind a collision group is simple: It optimizes the entire collision system.
As you might expect, a collision system
'
s algorithmic complexity grows with the
complexity of the geometry in question. Remove some of this geometry, and you
speed up your simulation. This is done by sorting objects into collision groups, essen-
tially lists of objects that can collide with one another and those that can
'
'
t. For exam-
ple, objects like a bunch of crates on the first floor can ' t collide with another group of
crates on the second floor if they are physically separated by something like an eleva-
tor. Set those objects into different collision groups, and your physics system will
thank you for it by running a few milliseconds faster.
Integrating a Physics SDK
Most programmers aren
ll most
likely grab a physics SDK off the shelf and integrate it into their game. Since I
'
t going to write their own physics system. They
'
'
m
 
 
Search WWH ::




Custom Search