Game Development Community

Toggling control from camera to player

by Laurence Grant · in Torque Game Engine Advanced · 12/24/2008 (12:51 pm) · 5 replies

Hey all,

I'm finally messing with TGEA, putting my other projects on the side for now and seeing if I can really make TGEA do what I want. I'm starting simple for now just trying to understand the basics for how the engine works, and something as simple as player vs camera is eluding me. More specifically the samples:

AtlasDemo you are just flying around with no collision detection. I guess somewhere you are mapped to control the camera not a player and therefore no collision detection. Can someone explain to me how I would add a player into the scene and change the controls to manage the player?


Similarly for ForgeDemo, we have a player standing there, but all I can do is move the camera around him. How is that setup? Where is it defined? How would I change it to put the player in control of that character?

Thanks

#1
12/25/2008 (4:13 pm)
I think I might be able to help. I have had loads of problems altering the camera, so have been playing around with it for a while.

In the atlas demo, you can add a player really simply. Just open up the scripts&assets folder of one of the tgea demos that has a player already in it. Go into the data folder and look for a folder containing the players, so in the t3d demo you need to go into data/shapes/players and take one of the player character data files (you will also need the animation file) and just copy it to the same location in the atlas demo data folder.

Then you need to go to the server scripts folder in the t3d demo (scripts&Assets/Server) and navigate till you find player.cs and other relevant cs files, just drag all the relevant files to the character you added the assets for, (you will need to take some other files like the crossbow.cs .... it should be obvious which files are relevant to a player).
Then you need to open up game.cs in the t3d server folder and again in the atlas folder. Then it's just a case of altering the relevant bitts (you should just be able to copy and paste from one file to the other), again it should be common sense which bits need changing. Functions like playerspawn, on cliententergame, you are looking for the following keywords: client, player and camera, and also anything related to any weapon you might be adding.
Finally you need to go into the client scripts folder and alter default.bind.cs so that it has some controls to move the player (these functions may already be their) and again just copy and paste from one folder to the other (with copying and pasting functions, make sure you paste over any existing functions, you don't want two functions with the same name)
As for the forge demo, it is just a case of repeating these steps; however it already has the data files for a player and the server files and the functions in default.bind, so all you actually need do is alter game.cs in the server folder. I suggest you have a try at getting a player to move around, if you get stuck just ask.

If you want to play around with the actual camera source to get different modes and effects, then you need to look at the advanced camera resource. If you don't fancy making all those changes, then you want to look at the afx core pack that has the advanced camera resource in it, as well as other stuff.

Hope this helps.
#2
12/26/2008 (10:43 am)
Awesome, thanks. Great overview. I appreciate it. Happy Holidays, I'll be busy playing now :-)
#3
12/28/2008 (8:32 pm)
I've been playing around and noticed all the code for player was already in game.cs so I just uncommented it and changed some of the code appropriately. I also commented out the code that was setting up the camera, as that same code is in spawnPlayer, but it sets the camera up differently. I copied the entire data/shapes from StrongHold to AtlasDemo, and I copied player.cs from StrongHold to AtlasDemo. It looks like everything is setup right, but I get this error in the console:

...game.cs (290): Register object failed for object (null) of class Player.

The line I uncommented was:

%this.spawnPlayer();

I thought line 290 is the line:

return %spawn.getTransform();

but now I'm not sure, because I added several error("print error message") lines above that, and it still says 290. Also, I printed spawn.getTransform(), and it's printing a valid transform, so it's not null, as the error indicated.

I looked at line 290 of player.cs and it's a blank line.

How do I debug this further to figure out what is really going wrong? Is there a debugger for the scripting, or just the console interface?

Thanks
#4
12/28/2008 (9:04 pm)
I figured out my problem. In the createPlayer I had :

%player = new Player() {
dataBlock = LightMaleHumanArmor;
client = %this;
};

but there was no LightMaleHumanArmor defined. The code I copied from StrongHold referenced PlayerBody, not LightMaleHumanArmor, I just changed the dataBlock line and its working.

I made a mistake with what line 290 was. Like a dummy I opened the file in ms word to view it, and word tries to page break things and took me to a different line. I realize I need to use a code editor in the future.

I'd still be interested in knowing the recomended way to debug script? Is there a debugger of any sort?
#5
12/28/2008 (9:44 pm)
There is Torsion which gets recommended to newcomers for it's "ease of use", try it out and see if you like it. Personally I found it limiting as a code editor, yet it is highly suited for Torque - only Torque - script debugging.