UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 8

219

PostBeginPlay()
{
....
/** called from UTPawn, spawns the default controller */
SpawnDefaultController();
....
}


  1. Now we need to do some work in our player controller class, in our case,
    TutorialPlayerController class. Let's add the variable array that we'll
    use to store the number of companions we want to spawn as shown in the
    following code snippet:
    /* Array used for setting the number of spawned companions
    /
    var Pawn Companions[3];

  2. Let's create a function in our TutorialPlayerController class to spawn
    these companions as shown in the following code:
    /*****

    • Spawns companion pawns
      *****/
      function PlayerSpawned(NavigationPoint StartLocation)
      {
      Companions[0] = Spawn(Class'TutorialPawn',,,
      StartLocation.Location - vect(75,100,0),
      StartLocation.Rotation);
      Companions[1] = Spawn(Class'TutorialPawn',,,
      StartLocation.Location - vect(150,120,0),
      StartLocation.Rotation);
      Companions[2] = Spawn(Class'TutorialPawn',,,
      StartLocation.Location - vect(200,280,0),
      StartLocation.Rotation);
      }




The fist parameter requires a class, so we're using our TutorialPawn class
as the pawn we want to spawn, and then we're setting the spawn location.
StartLocation.Location is where our pawn spawns, so we're offsetting
each of our companions by a bit, and then matching their rotation with ours,
so that we're all facing the same way upon spawning.
Free download pdf