UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 5

135

// declare it at the start so you can use it throughout the script
Var int _PathNode;
/** Distance our pawn needs to get to the node before it starts
looking for a new one */
var int CloseEnough;


  1. We need to override PostBeginPlay() in our class as well. All we're doing here
    is storing all of the PathNodes on a map to our array with the line WayPoints.
    AddItem( Current );.
    /*======================================================

    • Called right after the map loads
      =======================================================*/
      simulated function PostBeginPlay()
      {
      local PathNode Current;




/** Calls all of the PostBeginPlay functions from
parent classes*/
super.PostBeginPlay();
//add the PathNodes to the array
foreach WorldInfo.AllActors(class'Pathnode',Current)
{
WayPoints.AddItem( Current );
}
}


  1. Just as we had for our last AI Controller, we need to add event Posses.
    This tells our pawn to start moving as soon as the map loads.
    /*=======================================================

    • Forces the pawn to begin moving as soon as the map
      loads
      =======================================================*/
      event Possess(Pawn inPawn, bool bVehicleTransition)
      {
      super.Possess(inPawn, bVehicleTransition);
      Pawn.SetMovementPhysics();
      }



  2. We also need to override Tick(), which is called every frame. All it does is check
    that our pawn exists, and if it does, call our PathFind() function each frame.
    /*=======================================================

    • Called each frame
      =======================================================*/
      simulated function Tick(float DeltaTime)
      {



Free download pdf