Game Development Community

Implementing "Death View"

by Aleksander Elvemo · in Game Mechanics Kit · 10/22/2009 (7:08 am) · 8 replies

Hi there!

I wondered if anyone could point me in the right direction to how to implement a "death cam". What I mean is when the player is killed and spawns a ragdoll, I would like to still view from a first person view while tumbling about. So the camera never sets to a death orbit cam, but stay in the player Eyenode.

Using bullet and Torque 3d 1.0 =)

Thanks for any quick answers!

#1
10/22/2009 (1:02 pm)
I did that a while ago,
its not too difficult,
it does involve source changes though......

you'll need to merge over from player the camera suff into ragdoll,
you'll need to tell the ragdoll to become the controlling object on players death, and tell the camera to stay with the control object, on the players death.
#2
10/29/2009 (6:02 pm)
Thanks deepscratch for a major start push! =)

I've got almost everything camera related from the Player class to the Ragdoll class. The problem is finding out how much I must copy over. I also got most of the controlObject code, since that is also relevant i presume ;)

I'm currently at the stage where i wonder if i need more code, since when i try to set the ragdoll as a control object nothing happens, not an error, or the game shutting violently down, nothing ;)

Shall I post the functions I've copied over? Or could you give me a quick list?

Thanks for any reply! :)
#3
10/29/2009 (6:38 pm)
what does the log say at the point that the player dies?
#4
10/29/2009 (9:35 pm)
The log says this:
start createRagDoll()
It's a client!
end createRagDoll()

The function looks like this:
function createRagDoll(%ragdollData, %obj)
{
   echo("start createRagDoll()");
   
   %ragDoll_obj = new RagDoll(){}
            
    if(!%obj.aiPlayer){
       echo("It's a client!");
      %client = %obj.client;
      %client.camera.setTransform(%obj.getEyeTransform()); 
      %client.setControlObject(%ragDoll_obj);
    }
 
   echo("end createRagDoll()");
}

So as you can see, the function is almost the Stock GMK createRagdoll function, so i removed most of it for show here, only with added echoes and a test if the object has a client. If so then the camera is attached to the ragdoll instead of its previous attachment. Am I going at least the right way? or should i attach the camera another place? Also, I'm not getting any kinds of errors, which I find very odd.
#5
10/30/2009 (10:27 am)
ok, you got the right idea there,
but try this:
function createPlayerRagDoll(%ragdollData, %obj)
{
   %playerRagDoll_obj = new RagDoll() {
					position = "0 0 0";
					rotation = "1 0 0 0";
					dataBlock = %ragdollData;
				};
				
   %playerRagDoll_obj.initRagDoll(%obj);
   
   %force = VectorSub(%obj.getPosition(),%obj.damagePos);
   %force = setWord(%force,2,0);
   %force = VectorNormalize(%force);
   %force = VectorScale(%force,500);
   %playerRagDoll_obj.applyImpulse(%obj.damagePos,%force);

   %playerRagDoll_obj.getEyeTransform();

   %obj.client.setControlObject(%playerRagDoll_obj);
   %obj.client.camera.setTransform(%playerRagDoll_obj.getEyeTransform());

   return %playerRagDoll_obj;
}

I created seperate ragdolls for the player(playerRagDoll) and for npc's(npcRagDoll), cause the npc's dont need any of the camera stuff.
#6
10/30/2009 (6:42 pm)
Ahh, thanks for the clarification ;)

But still with your changes nothing happens, it just goes into ordinary death-orbit cam.

These are the function i ripped from Player and made Ragdoll;

void RagDoll::getCameraParameters
void RagDoll::getEyeTransform
void RagDoll::setControllingClient
void RagDoll::setControlObject
void RagDoll::onCameraScopeQuery
ShapeBase* RagDoll::getControlObject()

any obvious functions i have missed? =)
#7
10/31/2009 (6:19 am)
find this in game.cs,
if (isObject(%this.camera) && isObject(%this.player))
    {
        %this.camera.setMode("Corpse", %this.player);
        %this.setControlObject(%this.camera);
    }
and make it look like this:
if (isObject(%this.camera) && isObject(%this.player))
    {
        //%this.camera.setMode("Corpse", %this.player);
        //%this.setControlObject(%this.camera);
    }

problem with that is when you die, you'll need to exit the mission, then restart it to get player back, mouse click gets broken,
maybe you can find a work around....
if you do, post it.
#8
10/31/2009 (10:29 am)
Excellent! =D It works great now!

Well, I have no problem with spawning after I die, aaand rolling down the hillside in epicness!

I have halfway implemented the team-class resource for T3D, maybe that changes something, let me see.