Game Development Community

Updating Client Camera

by Stephen · in Torque 3D Professional · 08/02/2013 (4:24 am) · 15 replies

I have added the Advanced Camera resource to Torque 3D and I ran into a problem with the client mounts a vehicle. The clients camera stays where the client mounted the vehicle. I came across a fix that "Tom" posted but I'm not sure how to call the functions. I have tried but nothing is working.

www.garagegames.com/community/resources/view/5474/2#comment-62590

#1
08/02/2013 (5:39 am)
Quote:
in the mount vehicle function then jsut call the clear cmaera,

and on unmount clall useAdvCamera and ur set!

So call clear camera function in the on Mount vehicle function,

commandToServer('ClearCamera', %client);

not at my comp at min, using my iPad so can't tell you off hand the exact function name, same with the useAdvCamera function, in the vehicle unmount function.
#2
08/02/2013 (6:19 am)
scripts/server/commands.cs
function serverCmdClearCamera(%client) 
{
   //%client.clearCameraObject();
   echo("Restoring Camera (server)");
   %client.clearCameraObject();
}

function serverCmdUseAdvCamera(%client) 
{
   //%client.setCameraObject(%client.advanced);
   echo("Set up Camera (server)");
   
   // We set the camera system to run in 3rd person mode around the %player  
   %client.advCamera.setPlayerObject(%client.player);  
   %client.advCamera.setGodViewMode();  
   %client.setFirstPerson(false);
   %client.advCamera.setFollowTerrainMode(false);    
   %client.advCamera.setVerticalFreedomMode(false);    
   %client.setCameraObject(%client.advCamera);
}
scripts/server/player.cs
function PlayerData::onMount(%this, %obj, %vehicle, %node)
{
   // Node 0 is the pilot's position, we need to dismount his weapon.
   if (%node == 0)
   {
      %obj.setTransform("0 0 0 0 0 1 0");
      %obj.setActionThread(%vehicle.getDatablock().mountPose[%node], true, true);

      %obj.lastWeapon = %obj.getMountedImage($WeaponSlot);
      %obj.unmountImage($WeaponSlot);

      %obj.setControlObject(%vehicle);
      
      if(%obj.getClassName() $= "Player")
         commandToClient(%obj.client, 'toggleVehicleMap', true);
         
         commandToServer('ClearCamera', %client);
         
   }
   else
   {
      if (%vehicle.getDataBlock().mountPose[%node] !$= "")
         %obj.setActionThread(%vehicle.getDatablock().mountPose[%node]);
      else
         %obj.setActionThread("root", true);
   }
}
With this it only updates the server's camera.
#3
08/02/2013 (6:48 am)
looks like it should be Line 17 :-

commandToServer('ClearCamera', %obj.client);

thats from just a quick look.
#4
08/02/2013 (7:36 am)
That does not work.
#5
08/02/2013 (8:35 am)
change line 17 to

serverCmdClearCamera(%obj.client);

you only use the commandtoServer if you are calling it from a client, not a server script/method itself.

Also from the client, never pass the client parameter, as that is auto-generated like the %this is in namespacing. However, we pass it for this case because we are calling the command as an actual function ;)
#6
08/02/2013 (11:28 am)
I changed the function to.
function serverCmdClearCamera(%obj.client) 
{
   echo("Restoring Camera (server)");
   %obj.client.clearCameraObject();
}
Now Torsion is calling an syntax error with this function.
#7
08/02/2013 (12:59 pm)
// change this
function serverCmdClearCamera(%obj.client) 

// to this
function serverCmdClearCamera(%obj)
#8
08/02/2013 (4:17 pm)
So I have changed this in onMount,
commandToServer('ClearCamera', %obj.client);
Then in commands.cs
function serverCmdClearCamera(%obj) 
{
   echo("Restoring Camera (server)");
   %obj.client.clearCameraObject();
}
I get this in the console.log
Mapping string: ClearCamera to index: 3
Restoring Camera (server)
scripts/server/commands.cs (40): Unable to find object: '' attempting to call function 'clearCameraObject'
And the client mounts the vehicle but the clients body and camera stays in that position where the client mounted the vehicle. Once in the vehicle the client can not exit the vehicle. They must quit the game.
#9
08/02/2013 (5:10 pm)
you forgot to change the clear camera function back to:-

function serverCmdClearCamera(%client)   
{  
   //%client.clearCameraObject();  
   echo("Restoring Camera (server)");  
   %client.clearCameraObject();  
}

or

function serverCmdClearCamera(%obj)   
{  
   echo("Restoring Camera (server)");  
   %obj.clearCameraObject();  
}

it needs to use the same variable.
#10
08/02/2013 (6:34 pm)
With these variables, when the client enters a vehicle it changes the servers camera. Is there something else that is missing? I have started the project from the Empty template from the Project Manager. Then I have added the necessary functions.
#11
08/02/2013 (7:44 pm)
the serverCmd prefix auto-generates a client, which is why you don't pass in the client when using the commandToServer call function. Keep serverCmdClearCamera to this:

serverCmdClearCamera(%client)

and keep it as the client object itself, don't do %client.client as there is no client object on the client, it would be pointless. That is only used on the player (or other stuff idk) as the player holds a reference ID number for the client object.

Then, instead of using commandToServer, just use this in the onMount function:

serverCmdClearCamera(%obj.client);

So from your code, change this:

if(%obj.getClassName() $= "Player")  
   commandToClient(%obj.client, 'toggleVehicleMap', true);
commandToServer('ClearCamera', %client);


to this:

if(%obj.getClassName() $= "Player")  
{
   commandToClient(%obj.client, 'toggleVehicleMap', true);
   serverCmdClearCamera(%obj.client);
}


we also surround that part in the If statement, because why would the AI (if their would be AI) have to clear the camera?

keep this:

function serverCmdClearCamera(%client)   
{  
   //%client.clearCameraObject();  
   echo("Restoring Camera (server)");  
   %client.clearCameraObject();  
}
#12
08/02/2013 (8:27 pm)
Thank you Jeff. That works, it actives the function on the client correctly now but I ran into another problem. It's suppose to put the clients camera back into the godview like when the client first joins the server but it doesn't. So now when the client enters the vehicle it puts the clients camera in third person view. So I changed,
serverCmdClearCamera(%obj.client);
To
serverCmdUseAdvCamera(%obj.client);
But now we are back to where the camera doesn't update. Here's the UseAdvCamera function.
function serverCmdUseAdvCamera(%client) 
{
   //%client.setCameraObject(%client.advanced);
   echo("Set up Camera (server)");
   
   // We set the camera system to run in 3rd person mode around the %player  
   %client.advCamera.setPlayerObject(%client.player);  
   %client.advCamera.setGodViewMode();  
   %client.setFirstPerson(false);
   %client.advCamera.setFollowTerrainMode(false);    
   %client.advCamera.setVerticalFreedomMode(false);    
   %client.setCameraObject(%client.advCamera);
}
#13
08/02/2013 (8:45 pm)
Then add the call "%client.clearCameraObject();" in serverCmdUseAdvCamera before everything else. I thought %client.clearCameraObject(); was supposed to fix things or am I reading this wrong?
#14
08/02/2013 (8:54 pm)
I have just added "%client.clearCameraObject();" in the serverCmdUseAdvCamera before everything and it doesn't work. The camera doesn't update. Which leads me to believe that it might be something in the code.
#15
08/03/2013 (4:54 pm)
Any ideas?