Game Development Community

Detach camera on death problem

by Jesse P · in Torque Game Engine · 08/01/2008 (3:18 pm) · 14 replies

When the player dies the camera does not detach and orbit around the corpse. Instead for some reason my camera stays attached to the head and causes a funky looking problem since you are then able to rotate with the mouse and see inside the model. I have read that it should be detaching but for some reason mine is not. Any ideas why?

Here is what that section of my onDeath looks like in the game.cs

function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{

   //reset AmmoAmountHud
   %this.setAmmoAmountHud("0");

   // Clear out the name on the corpse
   %this.player.setShapeName("");

   // Switch the client over to the death cam and unhook the player object.

   if (isObject(%this.camera) && isObject(%this.player)) {
      %this.camera.setMode("Corpse",%this.player);
      %this.setControlObject(%this.camera);
   }


   %this.player = 0;

...

and here is what the the Observer::SetMode looks like in camera.cs

function Observer::setMode(%this,%obj,%mode,%arg1,%arg2,%arg3)
{
   switch$ (%mode)
   {
      case "Observer":
         // Let the player fly around
         %obj.setFlyMode();

      case "Corpse":
         // Lock the camera down in orbit around the corpse,
         // which should be arg1
         %transform = %arg1.getTransform();
         %obj.setOrbitMode(%arg1, %transform, 0.5, 4.5, 4.5);

   }
   %obj.mode = %mode;
}


Any ideas? Thanks

#1
08/01/2008 (3:43 pm)
That code looks correct. Try calling the onDeath function directly from within the console. Or do trace(true); in the console right before killing the player and ensure that the proper functions are being called.
#2
08/01/2008 (8:56 pm)
Look at the arguments being passed to setMode.
%this is getting "Corpse", %obj is getting the player object, and %mode isn't getting set.

I'm pretty sure only callbacks receive the first passed variable as the effected object automatically. And either way your mode should be after the player object, not before.
#3
08/02/2008 (10:26 am)
Actually, that only seems that way because he didn't post the Camera::setMode code which then calls the Observer::setMode with %obj being camera, %mode being Corpse and %arg1 being player. You don't directly pass %this as it is a method and is passed implicitly.
#4
08/02/2008 (11:09 am)
I'm not sure what the correct syntax should look like. It's weird because I tried it with a fresh install of the original unaltered build/install of TGE 1.5 and it has the same problem.

Is it suppose to detach and orbit around the body? That's what I really want it to do
#5
08/02/2008 (12:03 pm)
Here is the console.log when player kills self with trace(true):

Entering GameConnection::onDeath(1585, 0, 0, Suicide, Body)
               Entering GameConnection::setAmmoAmountHud(1585, 0)
               Leaving GameConnection::setAmmoAmountHud() - return 
               Entering Camera::setMode(1595, Corpse, 1596)
                  Entering Observer::setMode(22, 1595, Corpse, 1596, , )
                  Leaving Observer::setMode() - return Corpse
               Leaving Camera::setMode() - return Corpse
               Entering GameConnection::incScore(1585, -1)
                  Entering messageAll(8, , -1, 1585)
                     Entering messageClient(1585, 8, , -1, 1585, , , , , , , , , , , )
                     Leaving messageClient() - return 
                  Leaving messageAll() - return 
               Leaving GameConnection::incScore() - return 
               Entering messageAll(24, 25, 11)
                  Entering messageClient(1585, 24, 25, 11, , , , , , , , , , , , )
                  Leaving messageClient() - return 
               Leaving messageAll() - return 
            Leaving GameConnection::onDeath() - return
#6
08/05/2008 (8:13 am)
Any ideas?
#7
08/05/2008 (9:21 am)
Quote:Is it suppose to detach and orbit around the body? That's what I really want it to do

No, the standard camera doesn't "orbit" around the body, it just goes to a third person viewpoint of the dead player - usually showing half under the terrain.

If you want it to properly spin around looking down upon the corpse you'll probably have to use the Advanced Camera Resource.
#8
08/05/2008 (10:02 am)
Just going into 3rd person is fine with me, how would I get it to do that? Mine doesn't, it just stays attached to the head and looks terrible. It never went to 3rd person for me, even in a default original build, I'm using whatever the last version of TGE was, 1.5.x
#9
08/05/2008 (12:28 pm)
To be honest I have no idea why it doesn't. Your code seems to be the same as mine.

The only thing I can suggest is a slight code change to one of edits and move it down.
function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
   // Clear out the name on the corpse
   %this.player.setShapeName("");

//CHANGE
 //  //reset AmmoAmountHud
 //  %this.setAmmoAmountHud("0");
//to
//   %this.player.setAmmoAmountHud("0");

   // Switch the client over to the death cam and unhook the player object.
   if (isObject(%this.camera) && isObject(%this.player)) {
      %this.camera.setMode("Corpse",%this.player);
      %this.setControlObject(%this.camera);
   }
   %this.player = 0;

// And move it down HERE

%this.player.setAmmoAmountHud("0");

//script continues below as original...
//....

That's the only thing that I can really see that is different is your %this.setAmmoAmountHud("0");. Try taking it out and see what happens.
#10
08/05/2008 (3:04 pm)
Nothing changed, that is so weird. I tried even a fresh completely unaltered install of Torque and it does it there too...
#11
08/07/2008 (10:30 pm)
I can't possibly be the only one having this problem, it's doing it on a fresh install of TGE 1.5
This is so weird
#12
08/08/2008 (5:52 pm)
Hey Steve, I just added the advanced camera, what would I have to do to make it orbit on death, thanks
#13
08/08/2008 (9:19 pm)
I have no idea, I don't use the Advnaced Camera - but I'm under the impression you can lock a target with it, which sounds like what you want.

Myself, I just have the camera go to a waypoint marker which overlooks the level. I know that's not what you want but here's the code anyhow.
//I have a waypoint marker called deathcam in my mission

   if (isObject(%this.camera) && isObject(%this.player)) 
  {

//	%this.camera.position = %this.player.getposition();
//      %this.camera.setMode("Corpse",%this.player);
//      %this.setControlObject(%this.camera);

   if (isObject(deathcam))
	{
	%this.camera.position = deathcam.getposition();
	%this.camera.setMode("Corpse",deathcam);
	%this.setControlObject(%this.camera);
	echo("deathcam is here");
	}

   if (!isObject(deathcam))
	{
	echo("no deathcam node!");
	%this.camera.position = %this.player.getposition();
	%this.camera.setMode("Corpse",%this.player);
	%this.setControlObject(%this.camera);
	}
  }

Just had a thought - are you using a custom model or a Kork? If it's custom, check it has a cam node in it's skeleton/armature.
#14
08/08/2008 (9:37 pm)
Thanks, I'll try that, I kindof sortof got it to work in a similar way that goes to the orbit mode but resembles a marker observer in a similar fashion to what you have (which I think may ultimately be better), but the location of the marker is marked by the player's location which I guess is how the orbit works in the advanced camera, but it still has a few bugs and twitches a bit during the death animation, here's what I put in my onDeath

%this.advCamera.setPlayerObject(%this.player);
%this.advCamera.setOrbitMode();
%this.advCamera.setOrbitMinMaxZoom(100);
%this.advCamera.setOrbitMinMaxDeclination(45);
%this.setCameraObject(%this.advCamera);

instead of any of the "corpse" mode stuff, the first line sets the camera to look at the player (I assume)