Chapter One – Creating the Player Controller

February 4th, 2010 Leave a comment Go to comments

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 :

 

Game_IsometricGamePlayerController

 

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()

{

super.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 :

DefaultProperties

{

PlayerControllerClass=class‘IsometricGamePlayerController’

}

 

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

 

 

So it is alive if you look at the line before the ########## Finished loading level...

So it is alive if you look at the line before the ########## Finished loading level...

 

 

 

Chapter One – Creating the Isometric camera

 

 

 

Update me when site is updated
Share and Enjoy:
  • Print this article!
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Slashdot
  • Turn this article into a PDF!
  • Twitter
  1. Shad
    December 20th, 2009 at 19:15 | #1

    Une petite traduction francaise faite rapidement ! ^^ Ca peut peut être faire gagner du temps !

    Merci pour ce tuto.

    ———

    Maintenant que vous avez une base de jeu valide qui compile correctement, il est temps d’aller un peu plus loin. En suivant les même instructions que pour la classe “GameInfo”, créez à nouveau une nouvelle classe, et nommez le nouveau fichier “IsometricGamePlayerController”.

    Vous devriez obtenir une nouvelle classe héritée de “Object” comme le montre l’image suivante :

    Désormais, changez l’héritage de “Object” pour “GamePlayerController”. Qu’est ce qu’un “GameController” me direz-vous ? Cela permet de tenir compte des touches sur lesquelles appuis l’utilisateur et il est particulièrement utile pour contrôler un avatar unique qui représente la personne du joueur dans le monde en 3D que vous créez dans l’UDK.

    Donc, quand vous bougez la souris et que vous cliquez, les choses commencent dans cette classe. Cette classe va permettre à notre Intelligence Artificielle de donner a notre “Pawn” des fonctions de bases (tel le “Path Finding”) de tous les jeux modernes.
    La première chose que vous allez avoir envie d’ajouter est une fonction de test pour être sur que tout est correctement connecté depuis le “Game Info” jusqu’au “Player Controller”. Ajoutez la fonction suivante entre la déclaration de classe et le mot clé “DefaultProperties”.

    Désormais, cette fonction sera exécutée automatiquement lorsque le je commencera et sur entrée dans la console de la ligne de commande “RestartLevel”. L’indication “Super” permet d’exécuter la même fonction de la classe parent. C’est important si la classe parent faisait quelque chose, de garder ce qu’elle faisait, et d’y ajouter son propre code a la suite. C’est ce que l’on appelle “Function Overloading”. Si vous nêtes pas familier avec cela, prenez le temps de vous renseignez car cela ne fait pas partie du tutorial.

    Cependant, relier notre “Player Controller” à notre jeu requière plus que la simple création d’une classe. Nous devons indiquer à notre GameInfo d’utiliser le nouveau “Player Controller”, cela en utilisant les “DefaultProperties” de la classe “IsometricGameInfo”. Retournez à la classe “GameInfo” dans Visual Studio. Les “DefaultProperties” sont utilisées pour spécifier des valeurs par défaut aux différentes variables d’une classe.

    Par exemple, nous allons spécifier une nouvelle classe à utiliser comme “PlayerController”. Quand la “IsometricGameInfo” va être créée par l’UDK, il va chercher à cette variable pour savoir quelle nom de classe utiliser comme nouveau “Player Controller”. Ce processus est caché quelque part dans le code : vous pouvez aller y jetez un œil si vous voulez satisfaire votre curiosité, à la ligne 1097 du fichier “GameInfo.uc”.

    Rajoutez donc la valeur suivante :

    L’instruction de classe va dire au compilateur que vous êtes actuellement en train de spécifier un type de classe, par le texte entre guillemets.
    - Appuyez sur le bouton “Play” et inspectez votre “log”.

    Donc il est “Alive” si vous regardez la ligne avant le “########## Finished loading level”.

  2. Hotdot
    December 20th, 2009 at 22:23 | #2

    Merci Shad :) toute l’aide reçu est bienvenue !

  3. CaRteR
    December 31st, 2009 at 05:51 | #3

    I can’t get this to work. The code keeps failing in the build. (I wish I could read what the prior commenter said.)

  4. Daiboken
    January 16th, 2010 at 15:41 | #4

    There is an error with
    {

    PlayerControllerClass=class‘IsometricGamePlayerController’

    }

    Should be replaced with PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    PD: Many thanks to the author of this tutorial, it is helping me a lot :)
    This is why are you can’t get this to work Carter :)

  5. Hotdot
    January 17th, 2010 at 22:29 | #5

    Daiboken, maybe a UDK error, without the path for class’… works fine for me right now, you can specify it or not, its optional it seems.

  6. kugz
    February 2nd, 2010 at 11:05 | #6

    hey daiboken what version of the udk are you running cause ur solution is giving me the same error as the the original error. No disrespect to the author loving the tutorials but extremely hating this tiny errors brought about by using different versions of the udk

  7. Floboy
    March 15th, 2010 at 16:27 | #7

    Hey great tutorial but im stuck at this part , when i play at the end the game crashes and i log after Finished loadin level , i get
    ScriptLog: Couldn’t spawn player controller of class None
    Warning: Login failed: Engine.GameMessage.FailedSpawnMessage
    Critical: appError called: Could not spawn player
    Critical: Windows GetLastError: The system cannot find the file specified. (2)

    ive done just like in the tutorial :D im a noob with script so bare with me :D

  8. Hotdot
    March 15th, 2010 at 22:51 | #8

    did you use the fix for february release, it would seem that from the march version of UDK, the scripting require the folder as prefix to your class like the following :

    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    you can also always download the source code further down to check your file against the code that was tested. Your problem is pertaining to the playercontroller class not being created, so the main character cannot spawn and gives an error.

  9. David
    April 8th, 2010 at 23:46 | #9

    so i guess im still completely lost, i cannot for the life of me get anything to post to the cmd line script at all. any ideas why it might not post like its supposed to? (using march release of UDK atm just to clarify)

  10. Roychr
    April 12th, 2010 at 18:42 | #10

    David, to enable the command line console, you have to enable it in the projects settings of the unrealscript solution inside visual studio. Fall back to chapter 0 and be sure to set up the project properly, there are 3-4 options when launching from visual studio like disabling starting epic splashscreen, enabling console and some others. Its on the same page as where you specify your launching map. Hope I am answering to your question :)

    cheers !

  11. Effregy
    May 9th, 2010 at 04:05 | #11

    Despite using the fixed code version” PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’ ”
    I get
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’ Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’ Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’

  12. Moriteza
    May 12th, 2010 at 14:53 | #12

    @Effregy
    Dear Effregy u should use this script :
    class’MyIsometricGame.IsometricGameInfo’

  13. Neurotiq
    May 16th, 2010 at 11:23 | #13

    @Moriteza
    heres the problem.

    The UDK or UT Game.ini and UDK or UT Engine.ini have a glitch in them.

    I deleted my entire UDKGame folder then reinstalled UDK. Then did the first chapter over.
    It worked. The entry for game type is right at the top, and MyMod is easy to find because of the “;”

  14. Roychr
    May 18th, 2010 at 15:48 | #14

    This is hard trying to correct ghost bugs that are sometimes caused by the BETA state of UDK. Thanks Neurotiq.

  15. KlaarX
    June 2nd, 2010 at 06:25 | #15

    I had to write :
    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    instead of :
    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    to make this tutorial work with the UDK May release.

    Hope it will help.

  16. KlaarX
    June 2nd, 2010 at 06:27 | #16

    I had to write :
    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    instead of :
    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    to make this tutorial work with the UDK May release.

    Hope it will help.

  17. Mohannad
    June 23rd, 2010 at 13:54 | #17

    @KlaarX
    You are typing the same lines in fixed lines and the original, i see no difference, or am i blind? im using UDK May Release also and its still not working for me sadly, I get
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’ Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’ Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’

    still cant understand why >.<

  18. Mohannad
    June 23rd, 2010 at 16:44 | #18

    I managed fixing that, but now on the SCriptLog, I keep getting this error

    Cannot spawn player controller of class None

  19. June 23rd, 2010 at 17:24 | #19

    @Mohannad
    The quotes dont copy correctly, try retyping the single and double quotes on any line that has em.. i fixed these issues that way in mine. It happens when u copy over the code.

  20. June 23rd, 2010 at 17:48 | #20

    @Neurotiq
    oi, lol

    @*
    I have this working, about to move on to next stage, but am I supposed to be able to see the player model in this already cuz I can, the camera is inside him… following instructions to the letter, using VStudio2008+nfringe & May2010 UDK.. extending GameInfo not UTGame.

    ANOTHER BIG QUESTION,
    Since using nfringe with this setup before May2010 and then again after may 2010 UDK installation, I now get the following warning… shit still works, .u’s still get made from the .uc’s and all but the msgs worry me:

    UnrealScript.targets(0,0): warning : The script file ‘Classes\DWCamera.uc’ is not located in a folder recognized by the script compiler.
    UnrealScript.targets(0,0): warning : The script file ‘Classes\DWGameInfo.uc’ is not located in a folder recognized by the script compiler.
    UnrealScript.targets(0,0): warning : The script file ‘Classes\DWPlayerController.uc’ is not located in a folder recognized by the script compiler.

    Like I said they are getting compiled but something about the way we are using the things together seems to be lopsided/broken, any ideas?

  21. stephen
    June 29th, 2010 at 16:40 | #21

    I have tried everything, but no matter what I do, I get:
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’: Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’: Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Log: Game class is ‘GameInfo’

    I have tried every possible option posted, I tried typing everything in manually, I tried copying your code directly, I even tried overwriting my code with your sourcecode.

    Any help would be appreciated.

  1. No trackbacks yet.