Game Development Reference
//and back again
currentNode = waypoints;
//draw the paths in the scene view of the editor
//the node we are closest to at this moment
currentNode = graph.getPathPoint(currentWP);
Step 10. The preceding code adds extra paths between the original
circuit waypoints to point back the other way. This makes it possible
to travel in any direction between points. Extra paths are also added
between points in the driveway and out the front of the building. Play
and switch to the Scene to see the red lines connecting the points
(illustrated in Figure 5.10 ).
A new variable called currentNode has also been added to keep track of the
waypoint the character last visited. This enables the algorithm to plot out
paths based on the character's current position to the destination node.
This waypoint system is used in the next workshop after the development of a
self-motivated character is explained.
5.5 Finite State Machines
The most popular form of AI in games and NPCs is nondeterministic automata ,
or what is more commonly known as finite state machines (FSM). An FSM can be
represented by a directed graph (digraph) where the nodes symbolize states
and the directed connecting edges correspond to state transitions. States