Game Development Community

Exploding player when killed

by Chris Mooney · in Torque Game Engine · 12/17/2007 (10:55 am) · 3 replies

I would really appreciate any help anyone could give me.

I want to make the player explode when killed. Ive noticed code in player.cs that seems to be similar, I'd like to go for a debris type thing as with the crossbow explosion. I do remember it being used in a TGE project I worked on way back (probably 3 or 4 years ago), but I have no recollection of how we did it lol and really im just looking to make the player explode with any type of death.

Any help would be great!

Chris

#1
12/17/2007 (2:04 pm)
In Tribes 2 it had a function called blowup() that was accessible via script in order to make the object explode into pieces using the debris object defined in the model's datablock. I too wanted the same thing in Torque and it wasn't accessible via script, at least not easily for players.

So I went digging into the engine source code to see how I can add that functionality to the scripting language back. Here is how I ended up making it work:

Edit tge/engine/game/shapeBase.h and locate:
virtual void blowUp();

move it from being a protected to a public to another line, there is a public: keyword further down where you found the blowUp virtual prototype, just move the line below that. Be sure to save that change.

Next, edit tge/engine/game/shapeBase.cc and paste this code at the bottom of the source file:
ConsoleMethod( ShapeBase, blowUp, void, 2, 2, "Causes the object to explode into pieces.")
{
   object->blowUp();
}

This makes the blowUp() function exposed to the scripting language for shapeBase objects. Now to make use of the blowUp() function, open up tge/example//server/scripts/player.cs and locate this function:
function Armor::onDisabled(%this,%obj,%state)

Change this block of code
// Schedule corpse removal.  Just keeping the place clean.
   %obj.schedule($CorpseTimeoutValue - 1000, "startFade", 1000, 0, true);
   %obj.schedule($CorpseTimeoutValue, "delete");

to this one
// Schedule corpse removal.  Just keeping the place clean.
//   %obj.schedule($CorpseTimeoutValue - 1000, "startFade", 1000, 0, true);

   for(%i=0; %i<4; %i++)
     %obj.blowUp();

   %obj.startFade(50, 0, true);
   %obj.schedule($CorpseTimeoutValue, "delete");


There, next time your player dies it should provide a nice explode into pieces effect. The for() loop there is to cause it to blowup the same debris model four times to get a four times bigger exposion effect.

Almost forgot, make sure to do a recompile of Torque in order to see blowUp() accessible to the scripting language, do it for both Release and Debug (if you frequently use both to develop and test your game).
:)
#2
12/21/2007 (3:54 pm)
Hey Nathan,

Thanks for the reply, I will give that a try right away :), been out of town and forgot to check the thread :D. I'll reply on how it goes.

Chris
#3
12/21/2007 (4:14 pm)
Works perfectly :D!

Thank you! I'll have to credit you with the help :)! Im assuming the explosion data is from the player debris stuff from looking at the effects :D.

Thanks

Chris