Game Development Community

Advanced Camera on AIPlayer

by gamer · in Torque Game Engine · 01/30/2007 (5:04 pm) · 5 replies

Hi, I am trying to let a client gain control of the advanced camera that's targeted on an AIPlayer.
so I used ClientGroup.getObject(0).setControlObject(%aiPlayer.advCamera), but it crashes when this happen.

//create cameras on ai players
function AIManager::initCameras(%this){
    for(%i=0;%i<%this.players.count();%i++){
      %player=%this.players.getValue(%i);
      %player.advCamera = new AdvancedCamera() {
         dataBlock = AdvCameraData;
      };
      MissionCleanup.add(%player.advCamera);
         
      %player.advCamera.setTargetObject(%player);
      %player.advCamera.setPlayerObject(%player);
      //%this.advCamera.setThirdPersonTargetMode();
      //%this.advCamera.setGodViewMode();
      %player.advCamera.setOrbitMode();
 }
}
It works perfectly fine when that it's a regular Player instead of an AIPlayer. any idea why?
thanks

#1
01/30/2007 (5:09 pm)
I don't think you want to set the target and player objects to the same object. I usually leave the target unset, unless I'm specifically using one of the modes that needs it (the Orbit mode does not). Otherwise, I use an AdvancedCamera hooked to an AIPlayer, and it works fine for me.

Oh, also, you don't really need to create separate camera objects for each aiplayer. I find that when I just set the player object to a new AIPlayer, the camera automatically goes there (I keep a reference to my advanced camera in a dynamic variable in the client object).
#2
01/30/2007 (5:17 pm)
Bryan,
thanks I tried unset the target, but it still crashes the moment my client grabs the advanced Camera. any other advise?
#3
01/30/2007 (5:19 pm)
One more thing, are you calling something like 'ClientGroup.getObject(0).setCameraObject(%advCameraReference)' anywhere? You probably need to set the advCamera to be the given client's camera object.

Personally, I create my cameras in the GameConnection::onClientEnterGame(%this) method right below where the regular camera is created, store it in the client connection, and pretty much think of it as 'owned' by the client object, not the aiplayers. Then when I want to switch between aiplayers, I just set the advCamera's player object to the aiplayer I want to 'view' using setPlayerObject. Don't know if any of this has to do with why you're crashing when hooking it to an aiplayer, but it works for me this way.
#4
01/30/2007 (5:26 pm)
Here's an excerpt of the code that's working for me:
function GameConnection::onClientEnterGame(%this)
{
  //...other unrelated code here removed for clarity

   %this.advCamera = new AdvancedCamera() {
      dataBlock = AdvCameraData;
   };
   MissionCleanup.add(%this.advCamera);
   %this.advCamera.scopeToClient(%this);

  //...more code removed here

	%this.advCamera.setFollowTerrainMode(true);
	%this.advCamera.setVerticalFreedomMode(true);

       //I set these offsets here, since the player can switch between different sorts of advanced camera modes elsewhere
	%this.advCamera.setGodViewOffset("0 10 15");
	%this.advCamera.setThirdPersonOffset("0 -3.5 3.5");

  //...more other stuff

   %aiplayer = new AIPlayer() {
        dataBlock = PlayerBody;
        client = %this;
    };
    MissionCleanup.add(%aiplayer);

    //...etc...

   %this.advCamera.setPlayerObject(%aiplayer);

    %this.advCamera.setOrbitMode();  
    
    %this.setControlObject(%this.advCamera);
    %this.setCameraObject(%this.advCamera);   
}
Then, when I want to attach the camera to a new aiplayer, I just call:
%clientref.advCamera.setPlayerObject(%aiplayer);

on edit: forgot something
#5
01/30/2007 (5:43 pm)
I tried using just one single advCamera which belongs to my client and then change the playerObject dynamically to the AIPlayer, it works perfectly! I guess either changing setControlObject dynamically isn't a good idea or the advCamera must belong to the client, not the aiPlayer for it to work...
You saved me lots of pain!!
thanks!