A goalkeeper’s job is to keep the ball from traveling over the goal line. To
do this, a goalkeeper utilizes a different set of skills than a field player and
is therefore implemented as a separate class,
GoalKeeper. A goalkeeper will
move backward and forward along the goal mouth until the ball comes
within a specific range, at which point it will move outward toward the ball
in an attempt to intercept it. If a goalkeeper attains possession of the ball, it
puts the ball back in play by kicking it to an appropriate team member.
A Simple Soccer goalkeeper is assigned to the region that overlaps its
team’s goal. Therefore the red goalkeeper is assigned to region 16 and the
blue goalkeeper to region 1.
Along with having a completely different set of states than a field player,
GoalKeeper class must employ a slightly different setup for its motion.
If you observe a goalkeeper playing soccer you will notice that he is almost
always looking directly at the ball and that many of his movements are
from side to side, rather than along his facing direction like a field player.
Because an entity using steering behaviors has a velocity aligned heading,
a goalkeeper utilizes another vector,
m_vLookAt, to indicate facing direction,
and it’s this vector that is passed to the
Render function in order to trans-
form the goalkeeper’s vertices. The end result is an entity that appears to be
always facing the ball and can move laterally from side to side as well as
along its heading axis. See Figure 4.13.
170 | Chapter 4
Designing the AI
Figure 4.13. Goalkeeper movement