Game Development Community

User Guides -> Camera Modes

by Robert \"Larington\" Farr · in Torque 3D Professional · 09/01/2011 (8:04 am) · 8 replies

Hi,
I'm currently experimenting with a prototype where the game goes into a stationary camera for combat (looking at a hex grid) and whilst I can get the camera to go into the position and facing/direction I want, I'm having difficulty working out how to then set the camera back to the player character object in TorqueScript (which would happen once combat is over).

Could someone detail the code necessary to set the camera back to first person (might also be a good idea to add that information to the User Guide -> Scripting -> Advanced -> Camera Modes documentation section to help out anyone else considering doing something similar).

Thanks in advance

#1
09/02/2011 (3:11 pm)
Do a search for serverCmdToggleCamera(%client). Your answer is in that function.
#2
09/02/2011 (3:38 pm)
commandToServer('toggleCamera');

Thanks
#3
09/02/2011 (3:44 pm)
Well, it's more about the methodology of setting on the server, you may/may not want to use the toggleCamera command.

You may want to write our own version of ToggleCamera if you want it to do something specific. ToggleCamera is what is called when you hit alt c in the editor.
#4
09/02/2011 (4:46 pm)
For the moment I'm just slowly working on a quick and dirty prototype, but it also looks like I should be spending some time with the Maurina books to wrap my head around commandToServer and serverCmd(...). I should've thought to check for what alt-c calls, silly of me really. Thanks for the help though it's much appreciated.
#5
09/02/2011 (5:10 pm)
I'd love a twitter message letting everyone know that the CEO helped you out ;) Not many game engines would get that kind of message tweeted.

Btw...I found this post in a twitter message he posted.
#6
09/02/2011 (6:08 pm)
Dude - the commandTo's are the only way to fly if you want things to work right in multiplayer. HOWEVER - check my post about trigger callbacks for the caveat - "What happens on the server stays on the server (unless you show it to the client, I guess)." The moral of that story is "know where the server ends and the client begins" in the engine. Once you get that down the rest of that mechanism is cake. Oh, and mind your namespaces in your function param lists....

<edit>
And I'd like to point out that all of the books (Finney's and Maurina's) just give this mechanism a lick and a promise. You'll find that you learn more from experimenting with it after you cover it in the books.
#7
09/03/2011 (3:19 am)
I was doing some experimenting last night, see what would happen when I echoed get control object (a blank string as far as I can tell). I'm a designer that didn't complete an open uni programming degree (got most of the way in before stumbling badly on a Java module) so wearing programmers skin is an, uh, interesting challenge for me.

That said, I have found it quite easy to do a lot of things in Torque 3D - I could point out a city building game I was working on but abandoned because the design was caving in on itself rather than issues with Torque (Huge thanks for improving the documentation during the course of Torque's life, btw). http://larington.wordpress.com/2011/07/27/351/

@Eric - Will do, though I'll wait until the Americans wake up first, since a large chunk of my followers are West/East coast North America.

#8
09/03/2011 (6:34 am)
I did create my own custom functions in the end by the way.

/*
A lot of the functionality here will be pulling information from dynamic variables stored in the simgroup
including an array/list of all the nodes for that fight (The list will need to be generated in the code 
that makes the grid itself, of course.
Eventually we're going to need to start building function(s) to start handling the turn based system for
handling actions (moving, attacking, etc).
*/

//commandToServer('ViewpointChangeCombatBegins', %zoneManager.cameraPosition, %zoneManager.cameraFacing); 
function serverCmdViewpointChangeCombatBegins(%client, %cameraPosition, %cameraFacing)
{
   %client.camera.setVelocity("0 0 0");
   %client.camera.controlMode = "Stationary";
   %client.setControlObject(%client.camera);
   %client.camera.position = %cameraPosition;
   %client.camera.lookAt(%cameraFacing);
   clientCmdSyncEditorGui();
}

//commandToServer('ViewpointChangeCombatEnds');
function serverCmdViewpointChangeCombatEnds(%client)
{
   %client.player.setVelocity("0 0 0");
   %control = %client.player;
   %client.setControlObject(%control);
   clientCmdSyncEditorGui();
}

// Information on Typemasks can be found in this URL
// http://www.garagegames.com/community/forums/viewthread/88323
// Should find here what I need to create a special typemask for the combat nodes

function startHexBattle(%zoneManager)
{
   //These should provide me with pretty much everything I need to know for code in following blocks.
   echo("Camera Position: "@ %zoneManager.cameraPosition);
   echo("Camera Faces: "@ %zoneManager.cameraFacing);
   echo("First Node Name"@ %zoneManager.playerStartNode);
   %player1GoTo = %zoneManager.playerStartNode;
   echo("Camera Position: "@ %player1GoTo.position);
   
   //Camera and cursor settings defined in this code
   showCursor();
   
   
   //commandToServer('SetCameraMode', "FreeRotate"); //Stationary
   //LocalClientConnection.camera.position = %zoneManager.cameraPosition;
   //LocalClientConnection.camera.lookAt(%zoneManager.cameraFacing);
   commandToServer('ViewpointChangeCombatBegins', %zoneManager.cameraPosition, %zoneManager.cameraFacing);
   
   //Send all appropriate characters to their respective nodes
   //Need to add or use boombot code for this to work
   //Wonder if we can just cheat and swap boombot and standard player datablocks in/out at combat start/end
   //NOT YET: ClientGroup.getObject(0).player.SetMoveDestination(%player1GoTo.position);
   
   //Set $currentlyInBattle to true so that onMouseMove and other related button assignment is set
   $currentlyInBattle = true;
}