Game Development Community

[Solved] How to view other player's camera?

by Ted Southard · in Torque 3D Professional · 09/21/2010 (10:41 pm) · 4 replies

This is a bit frustrating.

Basically, I'm trying to implement an observer mode where when the player dies, they get to toggle through the camera's of the other players in the game, ala Call of Duty. The problem is, I don't seem to be able to do that. The toggling bit isn't hard at all, but when I try to test by just getting the view from another player's camera in dedicated server mode, I can see my own player, and still control it, but the camera's view does not rotate or move when the other player's does.

Has anyone had any success with this, or is the camera system dedicated to just looking from the player's point of view? Thanks in advance.

#1
09/22/2010 (9:44 am)
The easiest way I can think of right now is to set Camera as control object if the "dead player - GameConnection" and set the camera in orbit mode around the alive player.
With this, "dead" one can still have a look around, but will be "attached" to the selected player.

Example:
function attachClientToOtherPlayer(%deadPlayerConnection)
{
   // %deadPlayerConnection - the game connection (%client) of dead player.
   // %client - the gameConnection of alive player
   %client = 0;
   while(!%client)
   {
      %index = getRandom(0, clientGroup.getCount() - 1);
      %gameCon = clientGroup.getObject(%index);
      if(%gameCon.getId() != %deadPlayerConnection.getId() && %gameCon.getControlObject().getClassName() $= "Player")
         %client = %gameCon;
   }
   %deadPlayerConnection.setControlObject(%deadPlayerConnection.camera);
   %t = getWords(%client.getControlObject().getTransform(), 0, 2);
   %t = setWord(%t, 2, getWord(%t, 2)+1.5);
   %deadPlayerConnection.camera.setOrbitMode(%client.getControlObject(), %t, 3, 15, 8, false);
}
#2
09/22/2010 (8:05 pm)
Odd, when I try that I'm getting "Fatal SceneObject::resetWorldBox - Bad World Box!". I do get a valid client from the script though, so I'm not sure what the issue is.
#3
09/23/2010 (1:26 am)
@Fyodor: This is what works in my case, the rest being the same as yours. The offset and vectors are to taste, of course, but the last "true" locks the camera so the player only watches it as it moves with the player it "belongs" to.

%deadPlayerConnection.camera.setOrbitObject(%client.player, "0 0" SPC mDegToRad(90), 0, 0, 0, false, "0 0 2", true);

Thanks for the help, I was tearing my hair out on this one :)
#4
09/23/2010 (7:57 am)
glad to help :)