Game Development Community

Exploding .dts shape

by Richard Pettyjohn · in Torque Game Engine · 02/12/2007 (4:30 pm) · 24 replies

Is there a way to make .dts explode (or just be deleated)?

I did a quick search on exploding objects and I couldn't find anything.
Page «Previous 1 2
#1
02/13/2007 (4:40 am)
About halfway down the Torque 101: Intro to Torque thread...

Quote:
I'm trying to get the barrels to "explode" when they're hit by crossbow ammo.

I created a new explodingBarrels.cs file, and exec it.


Quote:

--------------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
// Exploding Shapes
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

datablock ExplodingBarrelData(explodingBarrel)
{
category = "Barrels";
class name = "BarrelClass";
shapeFile = "gameonefps/data/shapes/barrels/barrel01.dts";
};

//--collision detection of CrossbowBolt to barrel
function explodingBarrel::onCollision(%this, %obj, %col)
{

// only a collision by a CrossbowBolt causes explosion
if (%col.getClassName() $="CrossbowBolt")
{

//--if barrel is hit by CrossbowBolt then delete the barrel
%obj.delete();
}
};

--------------------------------------------------------------------------------



The console says:


Quote:

--------------------------------------------------------------------------------

GameOneFPS/server/scripts/explodingItems.cs Line: 19 - parse error
>>> Advanced script error report. Line 19.
>>> Some error context, with ## on sides of error halt:

--------------------------------------------------------------------------------


The ## is between class name and shapeFile like this

class name = "barrelClass";
##
##
shapeFile = gameonefps/data/shapes/barrels/barrel01.dts";


If I comment out the class name line, then the console says

Quote:

--------------------------------------------------------------------------------

unable to instantiate non-conobject class ExplodingBarrelData

--------------------------------------------------------------------------------

.


So is the problem with my shapeFile or is my BarrelClass wrong? A basic syntax error?

Thanks!!!

Tony
not a programmer
Infinitum3D
Member Posted: Dec 21, 2006 13:26
With alot of help, I was able to make barrels explode. They take damage from the crossbow bolts (and anything else that causes damage). This can be modified to make any shape "destroyable". Big thanks to Fucifer for the help.

I created a new explodingItems.cs file. (don't forget to load it using EXEC)

//--------------------------------------------------------------
Infinitum3D
Member Posted: Dec 21, 2006 13:26
With alot of help, I was able to make barrels explode. They take damage from the crossbow bolts (and anything else that causes damage). This can be modified to make any shape "destroyable". Big thanks to Fucifer for the help.

I created a new explodingItems.cs file. (don't forget to load it using EXEC)

//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
// Exploding Shapes
//-----------------------------------------------------------------------------

datablock StaticShapeData(ExplodingBarrelShape)
{
category = "Exploding Objects";
shapeFile = "~/data/shapes/barrels/barrel01.dts";
maxDamage = 100;
destroyedLevel = 10;
mass = 10;
friction = 1;
elasticity = 0.3;
explosion = ExplodingBarrelShapeDataExplosion;
// debrisShapeName = "~/data/shapes/barrel/barrel_debris1.dts";
// debris = StaticShapeDataDebri;
};

function ExplodingBarrelShape::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");
}
//-----------------------------------------------
//-----------------------------------------------


You can modify the amount of damage taken by the barrel by changing the maxdamage and destroyedLevel amounts. maxDamage is the maximum amount of damage done by the source, and the destroyedLevel is the amount of damage that can be taken by the target before being destroyed (like hit points).

Thanks!

Tony


I hope this helps!
#2
02/13/2007 (4:59 pm)
Thanks!
#3
02/13/2007 (5:37 pm)
If you want to dig deep go to this site. Thay have real good price on this pack and you will learn alot for good price.

www.3d-diggers.de/webshop/default.php?cPath=43_47_53&osCsid=114ad1eb8402e5d8bb27...
#4
02/14/2007 (5:26 pm)
Today I tried to add an explosion to the barrel.
For some reason the explosion doesn't seem to be working. I don't see what's wrong. This is basically copied from the crossbow explosion since I don't know enough yet to write my own.

Can some one please take a look at this and see if you see something wrong.

//-----------------------
// Explosion Debris
//-----------------------

datablock ParticleData(PropaneDebrisSpark)
{
   textureName          = "~/data/shapes/particles/fire";
   dragCoefficient      = 0;
   gravityCoefficient   = 0.0;
   windCoefficient      = 0;
   inheritedVelFactor   = 0.5;
   constantAcceleration = 0.0;
   lifetimeMS           = 500;
   lifetimeVarianceMS   = 50;
   spinRandomMin = -90.0;
   spinRandomMax =  90.0;
   useInvAlpha   = false;

   colors[0]     = "0.8 0.2 0 1.0";
   colors[1]     = "0.8 0.2 0 1.0";
   colors[2]     = "0 0 0 0.0";

   sizes[0]      = 0.2;
   sizes[1]      = 0.3;
   sizes[2]      = 0.1;

   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(PropaneDebrisSparkEmitter)
{
   ejectionPeriodMS = 20;
   periodVarianceMS = 0;
   ejectionVelocity = 0.5;
   velocityVariance = 0.25;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   orientParticles  = false;
   lifetimeMS       = 300;
   particles = "PropaneDebrisSpark";
};

datablock ExplosionData(PropaneDebrisExplosion)
{
   emitter[0] = PropaneDebrisSparkEmitter;

   // Turned off..
   shakeCamera = false;
   impulseRadius = 0;
   lightStartRadius = 0;
   lightEndRadius = 0;
};

// Debris smoke trail
datablock ParticleData(PropaneDebrisTrail)
{
   textureName          = "~/data/shapes/particles/fire";
   dragCoefficient      = 1;
   gravityCoefficient   = 0;
   inheritedVelFactor   = 0;
   windCoefficient      = 0;
   constantAcceleration = 0;
   lifetimeMS           = 800;
   lifetimeVarianceMS   = 100;
   spinSpeed     = 0;
   spinRandomMin = -90.0;
   spinRandomMax =  90.0;
   useInvAlpha   = true;

   colors[0]     = "0.8 0.3 0.0 1.0";
   colors[1]     = "0.1 0.1 0.1 0.7";
   colors[2]     = "0.1 0.1 0.1 0.0";

   sizes[0]      = 0.2;
   sizes[1]      = 0.3;
   sizes[2]      = 0.4;

   times[0]      = 0.1;
   times[1]      = 0.2;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(PropaneDebrisTrailEmitter)
{
   ejectionPeriodMS = 30;
   periodVarianceMS = 0;
   ejectionVelocity = 0.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 170;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   //overrideAdvances = false;
   //orientParticles  = true;
   lifetimeMS       = 5000;
   particles = "PropaneDebrisTrail";
};

// Debris object
datablock DebrisData(PropaneExplosionDebris)
{
   shapeFile = "~/data/shapes/crossbow/debris.dts";
   emitters = "PropaneDebrisTrailEmitter";
   explosion = PropaneDebrisExplosion;
   
   elasticity = 0.6;
   friction = 0.5;
   numBounces = 1;
   bounceVariance = 1;
   explodeOnMaxBounce = true;
   staticOnMaxBounce = false;
   snapOnMaxBounce = false;
   minSpinSpeed = 0;
   maxSpinSpeed = 700;
   render2D = false;
   lifetime = 4;
   lifetimeVariance = 0.4;
   velocity = 5;
   velocityVariance = 0.5;
   fade = false;
   useRadiusMass = true;
   baseRadius = 0.3;
   gravModifier = 0.5;
   terminalVelocity = 6;
   ignoreWater = true;
};

//---------------------------------
//explotion data
//---------------------------------

datablock ParticleData(PropaneExplosionSmoke)
{
   textureName          = "~/data/shapes/particles/smoke";
   dragCoeffiecient     = 100.0;
   gravityCoefficient   = 0;
   inheritedVelFactor   = 0.25;
   constantAcceleration = -0.30;
   lifetimeMS           = 1200;
   lifetimeVarianceMS   = 300;
   useInvAlpha =  true;
   spinRandomMin = -80.0;
   spinRandomMax =  80.0;

   colors[0]     = "0.56 0.36 0.26 1.0";
   colors[1]     = "0.2 0.2 0.2 1.0";
   colors[2]     = "0.0 0.0 0.0 0.0";

   sizes[0]      = 4.0;
   sizes[1]      = 2.5;
   sizes[2]      = 1.0;

   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(PropaneExplosionSmokeEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 4;
   velocityVariance = 0.5;
   thetaMin         = 0.0;
   thetaMax         = 180.0;
   lifetimeMS       = 250;
   particles = "PropaneExplosionSmoke";
};

datablock ParticleData(PropaneExplosionFire)
{
   textureName          = "~/data/shapes/particles/fire";
   dragCoeffiecient     = 100.0;
   gravityCoefficient   = 0;
   inheritedVelFactor   = 0.25;
   constantAcceleration = 0.1;
   lifetimeMS           = 1200;
   lifetimeVarianceMS   = 300;
   useInvAlpha =  false;
   spinRandomMin = -80.0;
   spinRandomMax =  80.0;

   colors[0]     = "0.8 0.4 0 0.8";
   colors[1]     = "0.2 0.0 0 0.8";
   colors[2]     = "0.0 0.0 0.0 0.0";

   sizes[0]      = 1.5;
   sizes[1]      = 0.9;
   sizes[2]      = 0.5;

   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(PropaneExplosionFireEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 0.8;
   velocityVariance = 0.5;
   thetaMin         = 0.0;
   thetaMax         = 180.0;
   lifetimeMS       = 250;
   particles = "PropaneExplosionFire";
};

datablock ParticleData(PropaneExplosionSparks)
{
   textureName          = "~/data/shapes/particles/spark";
   dragCoefficient      = 1;
   gravityCoefficient   = 0.0;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS           = 500;
   lifetimeVarianceMS   = 350;

   colors[0]     = "0.60 0.40 0.30 1.0";
   colors[1]     = "0.60 0.40 0.30 1.0";
   colors[2]     = "1.0 0.40 0.30 0.0";

   sizes[0]      = 0.25;
   sizes[1]      = 0.15;
   sizes[2]      = 0.15;

   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(PropaneExplosionSparkEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 1;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   orientParticles  = true;
   lifetimeMS       = 100;
   particles = "PropaneExplosionSparks";
};

datablock ExplosionData(PropaneSubExplosion1)
{
   offset = 0;
   emitter[0] = PropaneExplosionSmokeEmitter;
   emitter[1] = PropaneExplosionSparkEmitter;
};

datablock ExplosionData(PropaneSubExplosion2)
{
   offset = 1.0;
   emitter[0] = PropaneExplosionSmokeEmitter;
   emitter[1] = PropaneExplosionSparkEmitter;
};

datablock ExplosionData(PropaneExplosion)
{
   soundProfile = CrossbowExplosionSound;
   lifeTimeMS = 1200;

   // Volume particles
   particleEmitter = PropaneExplosionFireEmitter;
   particleDensity = 75;
   particleRadius = 2;

   // Point emission
   emitter[0] = PropaneExplosionSmokeEmitter;
   emitter[1] = PropaneExplosionSparkEmitter;

   // Sub explosion objects
   subExplosion[0] = PropaneSubExplosion1;
   subExplosion[1] = PropaneSubExplosion2;
   
   // Camera Shaking
   shakeCamera = true;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;

   // Exploding debris
   debris = PropaneExplosionDebris;
   debrisThetaMin = 0;
   debrisThetaMax = 60;
   debrisPhiMin = 0;
   debrisPhiMax = 360;
   debrisNum = 6;
   debrisNumVariance = 2;
   debrisVelocity = 1;
   debrisVelocityVariance = 0.5;
   
   // Impulse
   impulseRadius = 10;
   impulseForce = 15;

   // Dynamic light
   lightStartRadius = 6;
   lightEndRadius = 3;
   lightStartColor = "0.5 0.5 0";
   lightEndColor = "0 0 0";
};
#5
02/14/2007 (5:28 pm)
Fucifer, That pack looks pretty cool but I need to wait until I have enough extra money to upgrade to TGE 1.5 before I start buying any packs.
#6
02/14/2007 (5:57 pm)
Did you rename the explosion in the barrel's datablock?

datablock StaticShapeData(ExplodingBarrelShape)
{
   category       = "Exploding Objects";
   shapeFile      = "~/data/shapes/barrels/barrel01.dts";
   maxDamage      = 100;
   destroyedLevel = 10;
   mass           = 10;
   friction       = 1;
   elasticity     = 0.3;
   [b]explosion      = PropaneExplosion;[/b]
};
#7
02/14/2007 (6:15 pm)
Yes, I did. I couldn't post that part because it made my post too long.
#8
02/14/2007 (6:21 pm)
Did you put up the entire script because you have no functions?

What is not working with the explosion? I add your script to my function and it is working but dont know what you want.
#9
02/14/2007 (9:35 pm)
The propane tank disappears like it's supposed to, but the explosion with the particles and debris doesn't show up.
#10
02/15/2007 (8:25 am)
Ok, I will take look at it.

Look at following pictures to see if this is what you want. If so I need to see your function.

i141.photobucket.com/albums/r72/fuciferTorque/Propane2.jpg
i141.photobucket.com/albums/r72/fuciferTorque/Propane1.jpg
#11
02/15/2007 (11:30 am)
Would be nice if there was some decent explosion scripts around...
#12
02/15/2007 (5:02 pm)
Yes Fucifer that's what I'm trying to do. Here is the rest of the script:

datablock StaticShapeData(ExplodingBarrelShape)
{
category = "Exploding Objects";
shapeFile = "~/data/shapes/propane/propanedone.dts";
maxDamage = 100;
destroyedLevel = 10;
mass = 10;
friction = 1;
elasticity = 0.3;
explosion = PropaneExplosion;
};

function ExplodingBarrelShape::onAdd(%this,%obj)
{
%obj.playThread(0,"ambient");
}
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");
}

It's what Infinitum posted before.
#13
02/15/2007 (5:36 pm)
I did some research you need to rename your function. You should be good to go. I test this in TGE1.5.0 with no error in the console.

function StaticShapeData::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)

to

function ExplodingBarrelShape::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)

function StaticShapeData::onDamage(%this, %obj, %delta)

to

function ExplodingBarrelShape::onDamage(%this, %obj, %delta)

function StaticShapeData::onDestroyed(%this, %obj, %prevState)

to

function ExplodingBarrelShape::onDestroyed(%this, %obj, %prevState)
#14
02/15/2007 (9:02 pm)
I don't think that's the problem Fucifer.

It shouldn't matter whether the function is named StaticShapeData or ExplodingBarrelShape.

The only difference is the former will apply the function to all staticShapes and the latter will only apply it to the correspondingly named databock.

I'm going to take a stab in the dark and suggest that your explosion script is being executed after the staticShape functions script. Try executing the explosion script before the staticShape functions script.

Also, make sure the explosions script is being executing without error or warning (check the console).
#15
02/16/2007 (7:07 am)
Tim I try what you said and it work but I have found a problem. If you have two scripts for different objects they will conflict with one another. If I take the word Shape out of the line everything work good but I leave them in I get conflict on the shapeFile path. Do you have idea what could be cause this?

datablock StaticShapeData(FBarrelShape)

function FBarrelShape::onAdd(%this,%obj)

Change to

datablock StaticShapeData(FBarrel)

function FBarrel::onAdd(%this,%obj)
#16
02/16/2007 (8:14 am)
This is because it will override the already assigned function with the new one.
You could use packages to get around that by simply activating the package with that implementation when needed and otherwise the "default one" could be used (which seems to diable yours)
#17
02/16/2007 (8:25 am)
Do I have to use the Shape at the end? If I dont use it is there any problem that will come from this. I don get any error or warning if I dont use it in the console.
#18
02/16/2007 (7:56 pm)
Fucifer, I tried changing the names like you said but the propane tanks still won't explode.

Tim, how do I execute the explosion script first?


Also I found this in the console:

Loading compiled script tanks/server/scripts/propane.cs.
Object 'PropaneExplosion' is not a member of the 'ExplosionData' data block class

Is that a problem?
#19
02/16/2007 (8:08 pm)
Email me your script so I can look at it. I have what you post here and it is working find. There may be something you missing. Try this it is working for me without changing the names. Move this code to the bottom of the script.

function ExplodingBarrelShape::onAdd(%this,%obj)
{
%obj.playThread(0,"ambient");
}
#20
02/16/2007 (8:10 pm)
Quote:
Tim, how do I execute the explosion script first?

I'm not sure what your scripts are named but you should get the idea:

exec("./PropaneExplosion.cs");     // script with explosion
   exec("./ExplodingBarrelShape.cs"); // script with staticShape datablock & functions

That's all you need to do.
Page «Previous 1 2