UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 5

137

{
// Then set it back to zero and begin again
_PathNode = 0;
}
// Go to the Pathfinding state
GoToState('Pathfinding');
}


  1. The PathFinding state has the prefix Auto to denote that this is the default
    state the bot will start in. It checks if there are PathNodes in our array, and if there
    is one, starts moving towards it.


We use the function MoveToward() as it accepts an actor as a
parameter, and therefore we begin to move toward the actor. If we
wanted to use a vector instead, we would use the MoveTo() function.

/*=======================================================
* Auto state for our PathNode navigation.
=======================================================*/
auto state Pathfinding
{
Begin:
// Move to PathNode if one exists
if (WayPoints[_PathNode] != None)
{
MoveToward(WayPoints[_PathNode], WayPoints[_PathNode],
128);
}
}


  1. The final bit to add is in the default properties block. CloseEnough is the integer
    we used earlier, and we've seen bIsPlayer before as well.
    DefaultProperties
    {
    // Once we're within this man UU's of our Node....
    CloseEnough = 200
    // Pawn is a player or a player-bot
    bIsplayer = True
    }

  2. Load up our Ch5_PathNodes2.udk map, set Kismet to use our new controller and
    watch as the bot wanders from PathNode to PathNode in the same order you laid the
    nodes on the map!

Free download pdf