UnrealScript Game Programming Cookbook

(Chris Devlin) #1

Miscellaneous Recipes


220


  1. That's all there is to it! Compile the project and watch what happens when you spawn.
    You'll have three followers alongside you! They'll even follow once you reach a certain
    distance. They're following you because the player controller attached to their pawn
    class is following you.


How it works...


We override the SpawnDefaultFor() function in our TutorialGame class, which
spawns our default pawn in our TutorialGame class. Upon doing so, PlayerSpawned()
in our TutorialPlayerController class is to be called. This function spawns our
companion pawns.


We also tell our TutorialPawn class to spawn our default controller by making a call to
SpawnDefaultController(). This is actually defined in UTPawn, which is placed in our
PostBeginPlay() function so that our companions spawn right as the map finishes loading.


Finally, we create a function in our TutorialPlayerController class to spawn our
companions, with PlayerSpawned(). This simply takes an array, Companions[3],
which we defined at the top of the class, and spawns each one of them at a set location.

Free download pdf