Game Development Community

dev|Pro Game Development Curriculum

Damage and Destruction: Part6 - Player Bits and Pieces

by Michael Hall · 05/04/2012 (2:15 pm) · 13 comments



If you look within the Player datablock you'll notice these fields
debrisShapeName = "art/shapes/actors/common/debris_player.dts";
debris = playerDebris;
The PlayerDebris datablock and the debris_player.dts have been passed down through engine iterations ever since Tribes2, they've just been unused. They are to be used in order to "blowup" a player into chunks/gibs. Back in Part 2 of the Damage & Destruction series of Resources I demonstrated how to make use of a Debris Object when an object is destroyed and how it was different from the Explosion Debris. In response to a couple of questions on the Forums we noticed that this feature for the Player wasn't usable like it was for other Shapebase derived classes. This functionality is technically applicable to all ShapeBase derived classes, however the Player class overrides the inherited damage state control so that the Player class has no idea of the destroyed state sequence which can trigger an explosion and object breaking apart (simulated by debris).

I wanted to make this feature usable once again. Instead of rewriting the Player's damage state handling to follow that of the ShapeBase methods and have a suitable onDestroyed callback, I felt that it would be easier to simply make the Shapebase blowUp() method available to be used within script. This way you retain all forward/back functionality of the Player in your projects after applying this Resource. This gives us a practical demonstration of how to make use of that unused and undocumented debris_player.dts shape.


In shapebase.h find virtual void blowUp(); and move it down to within public: space instead of private:

In shapebase.cpp lets create our new console function which will allow us to call blowUp() from script. You can place it at the bottom of the file or located near all of the other damage/energy methods.
DefineEngineMethod(ShapeBase, blowUp, void, (),, "@brief Explodes an object into pieces.")
{
	object->blowUp();
}
Recompile.

Now in script, assuming a Full Template (or derivative project), we'll be looking at scripts/server/player.cs as well as making use of the aforementioned PlayerDebris datablock and player_debris.dts shape.

For a quick and simple demonstration let's introduce a modification to Armor::damage() where we will check for the Suicide damageType and blow the player into chunks. I placed the following within the if(isObject(%client){...} statement:
if(%damageType $= "Suicide")
{
   // This guy went to bits and pieces!
   %obj.blowUp();
         
   // Hide the player object.  onDisabled() will do further cleanup.
   %obj.startFade(50, 0, true);  
}

Save the script. Start the game, jump in a mission, and hit Ctrl+K to kill yourself: witness the body parts fly everywhere! Literally. The stock properties of the PlayerDebris datablock sends these things flying!

Just throw in some blood particles and maybe a bloody decal and you can make the effect look even better!

You could call blowUp() when a certain amount of excessive damage is taken in one hit, or upon a specific damagetype. I've written an Improved PlayDeathAnimation Resource that I think would be a great place to drop a player blowUp() call into. You could even use it as an admin option against naughty players! And of course you should modify the PlayerDebris datablock to your liking.

The player_debris.dts shape looks nothing like the soldier's bodyparts, and is untextured as well, but it will do for demonstration purposes. Check it out for an example of how to setup your own player debris shapes.
Quote: from Rex of BrokeAss Games:
The first boulderDebris.DTS [...] seemed to have some trouble 'breaking apart'. I think this was due to the shape's hierarchy. My first sample had a totally 'childless' chain in the hierarchy, or what I refer to has a 'flat' hierarchy; there is no 'parent' node in the Scene[or each node is a parent with no children]. This sample file didn't break up upon 'explosion'|'blowup', you got one single piece of geometry in the effect [...]

For the second sample [...], I changed the hierarchy slightly. I left the 'Root' node in the object to act as the 'parent' node and all of the geometry nodes were child nodes of the 'Root'. This seemed to give the shape it's needed hierarchy to 'explode' into fragments. I used Milkshape3D to export the DTS shape and with that exporter, you get a generated node for each piece of 'rigid' geometry[that geometry weighted to a SINGLE node influence]. I am not sure if a 'skinned' mesh object will act as a 'fragment' or not; the geometry may need to be 'rigid' or at least an 'object' in the shape's properties....sorry to toss some art babble into the code discussion, Michael, but I think it part of the exercise.

About the author

Been dabbling with game-programming since the age of 10 when I got my first computer, a Commodore. Got serious about game-development after modding Tribes for several years. Doesn't sleep much. Drinks rum. Teaches guitar. Plays cello.


#1
05/04/2012 (3:12 pm)
Wow! Awesome!
#2
05/04/2012 (11:03 pm)
Thats awesome! Ty for that resource and share.
#3
05/07/2012 (9:02 am)
Reminds me of the good old days of Tribes 2 :D
#4
05/08/2012 (1:59 am)
I like explosions... I can't wait to try this...
#5
06/09/2012 (1:22 am)
Quote:
" I left the 'Root' node in the object to act as the 'parent' node and all of the geometry nodes were child nodes of the 'Root'."

i have modify gideon.dts.
present node Hierarchy:
Quote:
Shape Hierarchy:

Details:
Detail6, Subtree 0, objectDetail 0, size 6

Subtrees:
Subtree 0
shape
Start
a1
a2
a3
a4
a5
a6
a7
a8
a9

Skins:
Skin head with following details: 6
Skin gideon with following details: 6


Sequences:

Material list:
material #0: 'head_d'.
material #1: 'body_d'.

but it is not working?
any idea?

here is my shape's script file:
http://pastebin.com/cnmnAqPb
#6
06/09/2012 (4:13 am)
@ahsan: did you break the Gideon model into chunks (individual meshes) and place each submesh as a child of the start or root node? I don't know if modifying the shape hierarchy through a TSShapeConstructor will actually work for this. Check out the debris_player.dts shape to see how it is setup.
#7
06/09/2012 (11:30 pm)
"did you break the Gideon model into chunks (individual meshes)"

no.i modified it into shape editor.
i named and modified it according to Hierarchy of debris_player.dts

i tried to save it using
ShapeEditor.shape.saveShape("newShape.dts").
but this command always crashed t3d.

where i can find source of gideon?
or
any importer or 3d app to import/modify dts file.




#8
06/10/2012 (12:36 pm)
I had thought one of the betas included source art for Gideon, but maybe I was wrong -- all I'm seeing is source for the animations and for the Soldier...

And yeah, you'll need to pre-break every shape that you want to use the blowUp feature for: players, vehicles, etc. It isn't procedural destruction, all it does is take these chunks and spew them out as debris.

Since you wont need the animations, you *might* be able to use the Export to Collada feature found in the Editor. Then you could modify that DAE, breaking it up, reskinning it and have Gideon debris.

#9
02/05/2013 (6:36 pm)
This is really cool!

I tweaked the players DebrisData datablock with some emitters for an added effect. And slowed the velocity down.

This is what I have so far.

The DebrisData datablock is found in player.cs
game/art/datablocks

The emitters are stock found in particles.cs
game/art/datablocks


datablock DebrisData( PlayerDebris )
{
   emitters[0] = "SmokeEmitter";
   emitters[1] = "TorchFireEmitter";

   explodeOnMaxBounce = false;

   elasticity = 0.15;
   friction = 1.5;

   lifetime = 4.0;
   lifetimeVariance = 0.0;

   minSpinSpeed = 40;
   maxSpinSpeed = 400;

   numBounces = 5;
   bounceVariance = 1;

   staticOnMaxBounce = true;
   gravModifier = 1.0;

   useRadiusMass = true;
   baseRadius = 1;

   velocity = 4.0;
   velocityVariance = 3.0;

};

#10
02/19/2013 (6:26 pm)
This looks very cool, got a video?
#11
08/01/2013 (12:44 am)
Anyone want to pull-request this?
#12
08/01/2013 (1:12 am)
@Daniel: it's actually on my list of "to be done"... but we would also want to improve the player debris shape to something that isn't bits and pieces of an unskinned Tribes 2 armor -- I retextured mine to look like chunks of meat!
#13
08/02/2013 (2:09 am)
Oh, what the heck. Just the console method for now, since that's all I need. Template scripts can be dealt with by someone who cares ;P.

EDIT: I made this:

i.imgur.com/3n2F6F7.gif

:D