Chapter One – Creating the Player Controller
Now that you have a valid and compiling game shell, its time to spice things up. Again create a new class following the same instruction as with the GameInfo class (see Creating Script Files for reference.). Name the new file “IsometricGamePlayerController”.
You should now have again a class that extends Object as the following image :
Now Change the extends Object to GamePlayerController. What is the Game Player Controller ? It handles user inputs and is specifically geared toward controlling a single avatar which represent the persona of the player in the 3d world you create with UDK.
So when you move the mouse and shoot, things will be computed in this class as a starting point. This class will hold our artificial intelligence to give our pawn basic functionality you would expect from a modern game such as path finding.
The first thing you will want to add is a test function to be sure everything is wired correctly from your game info to your player controller. Add the following function under the class declaration and the DefaultProperties keyword.
simulated event PostBeginPlay()
`Log(“I am alive !”);
Now this function is executed automatically when play begin and on a “RestartLevel” console function. The super directive tells that you will execute the function in the parent. This is important if the parent class was doing something, its better to keep doing it again and also add our own code afterward. This is called function overloading. If your not familiar with this, look it up by yourself because its not part of this tutorial.
Now to wire our player controller to our game, we need more than just create a new class. We need to actually instruct our GameInfo class to use this new player controller. This is done by using the DefaultProperties of the IsometricGameInfo class. Return to the GameInfo class inside Visual Studio. Now DefaultProperties are use to specify default values for member variables of a class.
For example we will specify a new class to use as PlayerController. When the IsometricGameInfo will be created by the UDK, it will look to this variable to know which class name to use to create a new player controller. This process is hidden away in the code somewhere, you can look it up to satisfy your curiosity its located on line 1097 of GameInfo.uc.
Add the following entry :
CORRECTIONS 04 feb 2010 : PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’ (end of chapter source code has this fix)
The class instruction tells the compiler that you are actually specifying a class type, specified by the text inside the quotes.
- Hit the play button and inspect the log