T3D has no StaticShape script example
by Steve Acaster · in Torque 3D Professional · 08/08/2010 (2:43 am) · 7 replies
As StaticShape is a fairly important class (if you want an object to do something other than just sit there), it's a bit odd that there has never been a StaticShape scripted example for newcomers to check in T3D. In fact those not in the know could be forgiven for thinking that there isn't a dynamic object class ready out of the box.
In the meantime, linky.
In the meantime, linky.
About the author
One Bloke ... In His Bedroom ... Making Indie Games ...
#3
StaticShape (and many other classes, like Player) inherit from ShapeBase, a VERY heavy monolithic class that is very difficult to work in/with and has a lot of stuff that can make it a nightmare to extend, and may make your last 10 percent of work take 90 percent of the time to wrap up, chasing bugs and network traffic that are a result of 10 years of layered, bad, untested coding.
The ShapeBase class is fine for prototyping, but for final production code, I would highly recommend NOT using anything that inherits from ShapeBase, but would consider creating a new class inheriting from GameBase (see KillerBunny's note in the source), and port only the functionality you need over from shapebase.
See the example classes in T3D/examples for clean classes that properly inherit from the chain (RenderMesh,RenderShape,RenderObject)... see the physicsshape examples to see clean and tight network traffic handling.
This doesn't apply so much to those that are making a simple FPS based on stock T3D, like your game, Steve, although you may be affected by the Mask bits. Just wanted to warn others before they spend months regretting the choice to use anything within the ShapeBase hierarchy. Unfortunately, this is where most people start within the code and I feel is a HUGE sticking point for anyone wanting to customize the game behavior in source. Looking at my SVN logs, you can see a marked decline in production at anytime I have to deal with these classes, luckily that is rare nowadays.
I hope TP addresses this issue soon... the commitment they are showing towards deprecating old features must eventually extend to these classes if the engine is to advance and become more multi-purpose out of the box.
08/08/2010 (2:17 pm)
One word of caution with an eye on the future:StaticShape (and many other classes, like Player) inherit from ShapeBase, a VERY heavy monolithic class that is very difficult to work in/with and has a lot of stuff that can make it a nightmare to extend, and may make your last 10 percent of work take 90 percent of the time to wrap up, chasing bugs and network traffic that are a result of 10 years of layered, bad, untested coding.
The ShapeBase class is fine for prototyping, but for final production code, I would highly recommend NOT using anything that inherits from ShapeBase, but would consider creating a new class inheriting from GameBase (see KillerBunny's note in the source), and port only the functionality you need over from shapebase.
See the example classes in T3D/examples for clean classes that properly inherit from the chain (RenderMesh,RenderShape,RenderObject)... see the physicsshape examples to see clean and tight network traffic handling.
This doesn't apply so much to those that are making a simple FPS based on stock T3D, like your game, Steve, although you may be affected by the Mask bits. Just wanted to warn others before they spend months regretting the choice to use anything within the ShapeBase hierarchy. Unfortunately, this is where most people start within the code and I feel is a HUGE sticking point for anyone wanting to customize the game behavior in source. Looking at my SVN logs, you can see a marked decline in production at anytime I have to deal with these classes, luckily that is rare nowadays.
I hope TP addresses this issue soon... the commitment they are showing towards deprecating old features must eventually extend to these classes if the engine is to advance and become more multi-purpose out of the box.
#4
08/08/2010 (2:29 pm)
Thanks for words of caution, Jameson. :)
#5
08/08/2010 (2:42 pm)
I have read it, but i have never played with the sound before. I'm looking for a nice simple explanation of how to set up sound. I have gathered from bits here and there that i need to set up an audio datablock etc.. but where, how, when? hehe if you get my meaning.
#6
Here's some 'generic' StaticShape methods that can be useful -- didn't want to clutter up your onCollision() example/resource:
You could also transfer these same methods to vehicles, rigidShapes, etc., namespaces -- anything that inherits from Shapebase actually.
EDIT: keep in mind that "destroyable" objects would require the maxDamage, disabledLevel, destroyedLevel, explosion, & debris/debrisShapeName properties of the shape being set in the datablock.
08/08/2010 (3:52 pm)
Quote:There's not??... ooops, my bad. I guess what happened was that when TSStatic was improved to automagically play ambient sequences (what most peopled used StaticShapes for) a StaticShape script-interactive example was overlooked - could have sworn I had though...
it's a bit odd that there has never been a StaticShape scripted example for newcomers to check in T3D.
Here's some 'generic' StaticShape methods that can be useful -- didn't want to clutter up your onCollision() example/resource:
function StaticShapeData::onAdd(%data, %obj)
{
echo("c4StaticShapeData::onAdd("@%data.getName()@", "@%obj@")");
// For 'simple' shapes there's not much for us to do here, but you could
// initialize dynamic properties, activate a startup sequence, set energy,
// recharge rate, repair rate, prepare for interaction, etc...
}
function StaticShapeData::damage(%data, %obj, %sourceObject, %position, %amount, %damageType)
{
echo("c4StaticShapeData::damage("@%data.getName()@", "@%obj@", "@sourceObject@", "@%position@", "@%amount@", "@%damageType@")");
if (%obj.isDestroyed())
{
//echo("object already destroyed, returning");
return;
}
%obj.applyDamage(%amount);
}
function StaticShapeData::onDamage(%data, %obj)
{
echo("c4StaticShapeData::onDamage("@%data@", "@%obj@")");
// Set damage state based on current damage level, we are comparing amount
// of damage sustained to the damage levels described in the datablock and
// setting the approppriate damageState
%damage = %obj.getDamageLevel();
if (%damage >= %data.destroyedLevel)
{
if (%obj.getDamageState() !$= "Destroyed")
{
%obj.setDamageState(Destroyed);
%obj.setDamageLevel(%data.maxDamage);
}
}
else if(%damage >= %data.disabledLevel)
{
// you could call an animation sequence here to represent the deformation
// of the object by damage. You can have as many sequences as you want,
// so long as you set up your damage amount to damage level comparisons
if (%obj.getDamageState() !$= "Disabled")
%obj.setDamageState(Disabled);
}
else
{
// we're just assuming that the object is still nice and healthy
if (%obj.getDamageState() !$= "Enabled")
%obj.setDamageState(Enabled);
}
}
function StaticShapeData::onEnabled(%data, %obj, %state)
{
echo("c4StaticShapeData::onEnabled("@%data@", "@%obj@", "@%state@")");
// We could do things here like establishing a power connection, activation
// sounds, play a start up sequence, add effects, etc.
}
function StaticShapeData::onDisabled(%data, %obj, %state)
{
echo("c4StaticShapeData::onDisabled("@%data@", "@%obj@", "@%state@")");
// We could do things here like disabling power, shutdown sounds, play a
// damage sequence, swap to an alternate model shape, add effects, etc.
}
function StaticShapeData::onDestroyed(%data, %obj, %prevState)
{
echo("c4StaticShapeData::onDestroyed("@%data@", "@%obj@", "@%prevState@")");
// If this is set to false then we delete the object when it is destroyed,
// we do so while it is still obscured by the explosion fx
if (!%data.renderWhenDestroyed)
%obj.schedule(200, "delete");
}Looking back I think those are heavily weighted towards destruction :DYou could also transfer these same methods to vehicles, rigidShapes, etc., namespaces -- anything that inherits from Shapebase actually.
EDIT: keep in mind that "destroyable" objects would require the maxDamage, disabledLevel, destroyedLevel, explosion, & debris/debrisShapeName properties of the shape being set in the datablock.
Torque Owner Chris Sargent
Glorious Software
Also, I may just be being silly but there really isn't anything on how to set up sounds either in the docs. There is a section on sounds but it is not really in a form that I can easily use to add sound to my game. I'm not using FMOD and there is a lot of that in there. How about just a simple tut on adding music or ambience to your project as well?
Thanks,