Game Development Community

Toggling First Person/Third Person

by Kamal Syed · in Torque Game Engine · 03/20/2004 (9:59 pm) · 22 replies

At the start of the Racing game, the mode is always set at 1st Person. Instead, I would like it to start in 3rd person. I've checked the scripts but wasn't successful in finding any traces of the TAB command. All that I see is that it leads to ToggleFirstPerson function, but it stops there. Is this part of the C++ code? If so, can you please direct me on how to fix it? If not, likewise, can you tell me where in the code I can manage to fix this?

Thanks.
Page «Previous 1 2
#1
03/21/2004 (11:12 am)
Have you tried doing a find in files for ToggleFirstPerson?
#2
03/21/2004 (1:54 pm)
Yes I have Ben, and that was before I wrote my first post. Unless I am searching for the wrong item altogether, "ToggleFirstPerson" is mentioned only 5 times in the Racing mod:

Twice in starter.racing\client\scripts\default.bind.cs
Once in starter.racing\client\config.cs
Once in starter.racing\client\scripts\optionsDlg.cs
Once in starter.racing\client\scripts\client\config.cs

As far as I know that is all, and none of the results lead anywhere or to any function/procedure that deals directly with "how" to toggle the 1st Person/3rd Person POV. I wouldn't have made my post without attempting to fix the problem in the first place, but I tried to solve it, yet to no avail.
#3
03/21/2004 (2:01 pm)
I'd say go into server/scripts/game.cs - and onClientEnterGame (or something similar to that) insert a

$firstPerson = false;

You can change $firstPerson anywhere and that's all it really takes.
#4
03/21/2004 (2:05 pm)
I tried to fiddle with this too. Unless I want to hardcode it into the engine to start in 3rd person (I think its in the GameConnection class), I had to resolve to the server setting the 3rd person view when the client joins the game.

Its a matter of controlling the $firstPerson variable basically on the client side. Set it to 0 and you get 3rd person, set it to 1 and its 1st person. My problem has been to find the right place to set it, as all my tests have failed except this one:

To the client game.cs I added the following 2 functions
function clientCmdCameraToThirdPerson()
{
   $firstPerson = 0;
}

function clientCmdCameraToFirstPerson()
{
   $firstPerson = 1;
}

And to the server game.cs I add the following to the GameConnection::onClientEnterGame()

function GameConnection::onClientEnterGame(%this)
{
   commandToClient(%this, 'CameraToThirdPerson');

Not very elegant, but it works like a charm. If anyone can get this to work by simply writing $firstPerson = 0; somewhere on the client side, then tell me where to add it please.....
#5
03/21/2004 (3:10 pm)
Thank you Steven and Thomas. That did the trick.
#6
03/25/2004 (12:25 pm)
Hello guys. I am currently attempting to do the same thing. I did exactly what Thomas did, but it still did not work.

What I've found so far is that you can change the $firstPerson variable no problem, but this will only effect the camera placement if done before a camera update.

Since the camera is updated to the eyetransform of the player when the player is created, it seems like the $firstPerson flag has no effect.

It is very strange it seems to work sometimes but not others.

If I solve this mystery i will certainly let you all know what I did.
#7
06/25/2004 (7:31 am)
Is it so bad to put it in the source code ?
I mean, beeing a first person shooter or a third one seems to be really important enough to be hardcoded.

gameConnection.cpp - Line 37 :
"bool GameConnection::mFirstPerson = true;"

Set it to false.
#8
09/17/2004 (9:13 am)
In my game I, I just set:

$firstPerson = false;

and removed the keybinding to switch camera views.. It's low-tech but it worked :)
#9
03/11/2006 (12:38 pm)
My game would not start in 3rd person even if $firstPerson was set to false. I did however get it to work.

Make sure that $firstPerson=false in default.bind.cs and to keep things simple delete or comment out any other $firstPerson= something scripts so you won't accidentally override the value of $firstPerson in default.bind.cs.

In game.cs add this to function GameConnection::onClientEnterGame (I put it at the bottem):

ServerConnection.setFirstPerson($firstPerson);


I tested this in 1.4. If you set that $firstPerson back to true in default.bind.cs, you will start in first person again. This might be hand for you if you want to use this as part of a game template.
#10
06/05/2006 (5:44 pm)
Thank god.

I've been looking for this for ages and haven't seemed to be able to find a way to default to 3rd person. So thanks Greg (even if it was months ago)

I'll also add that (for me atleast) it wasn't neseccary to remove or edit out any other things that dealt with $firstperson. I simply put:

ServerConnection.setFirstPerson(false);

as the last line of in GameConnection::onClientEnterGame in the server game.cs and voila. I enter the mission in 3rd person. I will eventually be loading a value from the preferences set by the player to replace the hard-coded 'false' so that the player can choose whether to go in 3rd or 1st person.
#11
06/05/2006 (9:25 pm)
Simply toggling $firstPerson never worked for me; ServerConnection.setFirstPerson() was the only thing that worked.
#12
08/08/2006 (12:46 am)
Got the last one to work, and i've tried them all now, i think. Thnx for the help!
#13
06/04/2007 (11:22 am)
I see it's been a while since someone posted here, but if anyone is still around I've got a question.

I've been trying to do something similar. I've got a game that the player has the option of choosing different vehicles to start with. The player is actually spawning as the vehicle. After they choose their vehicle I want to start them in third person view. Then when they die I want to send them back to first person, where a dialog comes up to allow them to choose another vehicle to spawn with, then put them back in third person when they respawn again.

I've been unable to get the player to start in third person view. I've tried adding "$firstPerson=false" to the spawnPlayer() and createPlayer() functions and have tried tinkering with a few other things with no good results.

Should I be trying to set $firstPerson=false somewhere else, or have I just been doing it wrong? If I get that working will I be able to set $firstPerson=true "onDeath" and the back to false again when they respawn?

Sorry if that all sounds a little confusing, but if anyone can make sense of this, any help or pointers will be greatly appreciated.

Thanks,
Myke

P.S. If it makes any difference, I'm also using the advanced camera.
#14
07/10/2007 (12:30 pm)
I just find out an ez way to do this, in server/scripts/game.cs add:

function GameConnection::onClientEnterGame(%this)
{
   commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);

   %this.camera = new Camera() {
      dataBlock = Observer;
   };
   MissionCleanup.add( %this.camera );
   %this.camera.scopeToClient(%this);

   %this.score = 0;

/************************************************************/
   [b]ServerConnection.setFirstPerson(false);[/b][i]// Just add this line[/i]

/************************************************************/

   %this.spawnPlayer();
}

that will start the game in 3rd person.

cheers
#15
07/10/2007 (4:37 pm)
Thanks for the tip. I did actually end up getting it work how I wanted using the "ServerConnection.setFirstPerson();". It was just a matter of tinkering and finding the right places to put it.

Thanks again.
#16
08/21/2007 (12:19 pm)
I have tried all these and works well when playing on the machine that starts the server (local client), but I have not been able to start a non local client on 3rd person view...

any one else know what to do?

Thanks
#17
09/03/2007 (1:59 am)
Know it's been a while since you posted the question, but in function GameConnection::onClientEnterGame(%this) use :

%this.setFirstPerson(false);
#18
04/10/2008 (12:33 pm)
When working with this I found out I was using a call to connect("server") directly.
this did not properly set up GameConnection(ServerConnection) so ServerConnection was not a valid object.

I now use a function called properConnect to connect directly to servers for debuging.

function properConnect( %address, %name, %password )
{
%conn = new GameConnection(ServerConnection);
%conn.setConnectArgs(%name);
%conn.setJoinPassword(%password);
%conn.connect(%address);
}

I thought this might be useful for someone to know.
#19
05/03/2008 (4:40 am)
I know it's been quite awhile since you posted Greg...but THANK YOU!!!! And thank you Kamal for posting the question!
#20
05/03/2008 (9:56 am)
OnClientEnterGame is a SERVERSIDE function. ServerConnection is a CLIENTSIDE object. That is why accessing ServerConnection from onClientEnterGame is incorrect and only worked for single player ( because in single player the client is the server and therefore Clientside vars are accessible from the Serverside code ).

So, use %this not ServerConnection.
Page «Previous 1 2