O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

}
//no target to shoot at so rotate facing to be parallel with the bot's
//heading direction
else
{
m_pOwner->RotateFacingTowardPosition(m_pOwner->Pos()+ m_pOwner->Heading());
}
}
Notice how when the aiming position is predicted, a line-of-sight test must
be made to ensure the predicted position is unobstructed by walls. This is
not necessary if the weapon is aimed directly at the target because the LOS
to the target position is cached when the target’s memory record is updated.
Notice also how immediately before the weapon is fired, some noise is
added to the aiming position in order to prevent the shot from hitting the
target 100 percent of the time.
z
TIP For some games it’s a good idea to ensure an AI controlled agent always
misses the first time it takes a shot at the player. This is because the shot will
warn the player to the presence of the agent, enabling him to take appropriate
action without getting hurt immediately. This is particularly useful for scenarios
where a player often enters unexplored rooms full of baddies because it gives
him a chance to retreat a little and take stock of the situation instead of getting
unexpectedly slaughtered.
Also, when deliberately shooting to miss, if the projectile or its trajectory can
easily be seen (like a rocket or arrow), you can add to the excitement by ensur-
ing the shot passes close by and within the player’s field of view.
Another good aiming tip is this: If the player’s health is very low, reduce the
aiming accuracy of any bots shooting at him. This way he gets a chance to pull
off an amazing recovery, which will enhance his game playing experience signif
-
icantly. (He gets to feel like Aragorn in the Battle for Helm’s Deep instead of like
Paul Newman and Robert Redford in the last few minutes of Butch Cassidy and
the Sundance Kid!)
Putting It All Together
Figure 7.8 shows how the AI components discussed in the last few pages
interrelate. Note how the
Goal_Think object has no direct control of
low-level components such as movement and weapon handling. Its purpose
is to arbitrate between and manage the processing of high-level goals. Indi
-
vidual goals utilize the lower-level components as and when required.
Raven: An Overview | 327
AI Implementation

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required