UnrealScript Game Programming Cookbook

(Chris Devlin) #1

AI and Navigation


144

How to do it...


We've covered enough wandering and patrolling up to this point. Why not create an AI which
is more friendly, and can follow us around a map? I'm sure you've played a game where one
character follows another, whether it is the shadow ninjas in Ninja Gaiden on the NES, or the
president's daughter following Leon in the more recent Resident Evil franchise. Ever wonder
how the characters do that? It's time to explain how.



  1. Create a new class called FollowBot. Have it extend from AI Controller.
    class FollowBot extends AIController;

  2. We're going to need four variables for this one. Some of them we've already seen
    from previous examples, but they are all pretty well explained in the comments.
    /* Whatever target we'd like to use. In this case, our
    pawn
    /
    var Actor target;


/** The temporary destination the pawn will be headed
toward
(PathFinding) */
var() Vector TempDest;

/** PathNode Array */
var array<Pathnode> WayPoints;

/** Distance our pawn needs to get to the node before it
starts
looking for a new one */
var int CloseEnough;


  1. Add the event for Possess, just as we've done with our other bots.
    /*=======================================================

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



Free download pdf