Adding a destructible ShapeBaseData object?
by Stephen Clark · in Torque Game Engine · 02/19/2003 (1:40 pm) · 9 replies
So I am trying to add an object using the world editor creator that can be destroyed. My first question is should I be using a ShapeBaseData object? And then when I do add an object of this type it doesnt appear. Adding the same object as a Static makes it appear correctly. I have tried adding playing the ambient animation to the OnAdd and addToScene events but it still doesnt appear. Also, I am confused as to whether I have to handle my own damage variables or is there something built-in to take care of this.
Thanks,
Stephen
Thanks,
Stephen
datablock ShapeBaseData(MyBox)
{
MaxDam=100;
category="My Items";
shapefile="./testcube.dts";
};
function ShapeBaseData::create(%block)
{
error(%block);
%obj = new ShapeBaseData(){
dataBlock = %block;
};
return %obj;
}
function MyBox::addToScene(%this,%obj)
{
%obj.playThread(0,"ambient");
}
function MyBox::OnAdd(%this,%obj)
{
%obj.playThread(0,"ambient");
}
function MyBox::damage(%this, %obj, %position, %source, %amount, %damageType)
{
echo("ive been damaged!");
}
#2
Thanks,
-s
02/20/2003 (2:40 pm)
Ok, so ShapeBase is not the correct class to be using. So what is then? I would like something destructible that can play animations. Another user had a similar question Gabriele Z or something, but I didnt see a final resolution to the problem.Thanks,
-s
#3
If you havent already, run through ToRK's vehicle tutorial, to get an idea of how the vehicles do the destruction thing.
tork.zenkel.com, check the tutorial section, for a flying vehicle tut. Comes with .dts .
02/20/2003 (3:39 pm)
As far as I know, you need to subclass ShapeBase. Look to the code in marker classes as an example of a very simple shapebase subclass. Look to the code in the vehicle classes for examples of destroyable shapebase objects.If you havent already, run through ToRK's vehicle tutorial, to get an idea of how the vehicles do the destruction thing.
tork.zenkel.com, check the tutorial section, for a flying vehicle tut. Comes with .dts .
#4
Try this:
of course you need datablocks for your debris and explosions...
02/20/2003 (5:51 pm)
Is StaticShapeData() the type you are looking for? Here's what I'm using to make destroyable objects. Try this:
datablock StaticShapeData(TestShape)
{
category = "Break Stuff";
shapeFile = ="./testcube.dts";
maxDamage = 100;
destroyedLevel = 100;
mass = 10;
friction = 1;
elasticity = 0.3;
explosion = TestShapeDataExplosion;
debrisShapeName = ="./testcube_debri.dts";
debris = StaticShapeDataDebri;
};
function TestShape::onAdd(%this,%obj)
{
%obj.playThread(0,"ambient");
}
//---------------------------------
//General StaticShapeData functions
//---------------------------------
function StaticShapeData::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
echo("Blowing stuff up");
%obj.applyDamage(%damage);
}
function StaticShapeData::onDamage(%this, %obj, %delta)
{
%damage = %obj.getDamageLevel();
if (%damage >= %this.destroyedLevel)
{
if(%obj.getDamageState() !$= "Destroyed")
{
%obj.setDamageState(Destroyed);
}
}
else
{
if(%obj.getDamageState() !$= "Enabled")
%obj.setDamageState(Enabled);
}
}
function StaticShapeData::onDestroyed(%this, %obj, %prevState)
{
%obj.schedule(300, "delete");
}of course you need datablocks for your debris and explosions...
#5
03/28/2006 (9:42 am)
Is it possible to get the above script to work with interiors? it doesnt work when i try.
#6
03/28/2006 (12:01 pm)
No it isn't. Interiors cannot be created or deleted at runtime by default, nor do they have any damage code associated with them.
#7
03/28/2006 (3:32 pm)
I have done a debris datablock, but not an explosion datablock. What might that look like?
#8
03/29/2006 (6:15 pm)
There is one in crossbow.cs the thing you would need is debris that looked like cracked peices of your object, and maybe explosion particles for dust, sparks, etc.
#9
05/17/2006 (4:40 pm)
The object is exploding at right time every thing look good. Tring to get an explosion when the object is destroy. i am using kevin setup above. How would I tied the datablock explosion into the function to get it to work correct.
Torque Owner Paul Scott
Default Studio Name
It contains a subclass of shapebase. The subclass overrides ::onAdd() and ::onRemove() are most important to you. Not all ShapeBase subclasses want to be visible all the time, so ShapeBase does not make a call to addToScene(), in its own ::onAdd(). All the ShapeBase subclasses that you are able to see at some time or other call addToScene() when they are ready to show themselves, and call removeFromScene() when they want to hide.
So, I think that its impossible to add a raw ShapeBase to the world, and *See* it, because ShapeBase does not call addToScene().