Game Development Community

Destructible Objects

by Britt Scott · in Torque Game Engine · 08/25/2008 (8:32 pm) · 3 replies

I'm having problems getting an object to play a "destroyed" animation by shooting it. The animation works fine when I ram the player into it. I, however, can't get projectiles to destroy it. The animation is being played in onCollision. I believe the projectile is fine as far as I know. I can see it fire from the gun. It also leaves bullet hole decals on terrain and interiors. I remember the code working in 1.4, but I'm having no luck with TGE 1.5.2. Thanks.

About the author

Attended Brown College in Mendota Heights, MN for Game Design and Development. Projects include the Mech Starter Kit and the Battle Frog. Currently working toward a game design career.


#1
08/26/2008 (4:09 am)
Are you playing the animation on player collision or projectile collision?

From reading your post it sounds like you are doing it on player collision and not projectile:
Quote:The animation works fine when I ram the player into it. I, however, can't get projectiles to destroy it.

I recommend you look into this as that may be your problem. :)
#2
08/26/2008 (5:59 am)
Would I need to put it in onDamge or Damage? Code of what I have so far, below:
///////////////////////////////////////////////
function StaticShapeData::create(%data)
{
   // The mission editor invokes this method when it wants to create
   // an object of the given datablock type.
   %obj = new StaticShape() {
      dataBlock = %data;
   };
   return %obj;
}
///////////////////////////////////////////////
datablock StaticShapeData(ShootableTarget)
{
   category = "Interactive";
   shapeFile = "~/data/shapes/Targets/Target.dts";

   maxDamage = 20;
   destroyedLevel = 20;
   debris = "TargetRedDebris";
   disabledLevel = 0.25;
   renderWhenDestroyed = false;
};
///////////////////////////////////////////////
function ShootableTarget::create(%block)
{
   %obj = new StaticShape()
   {
      dataBlock = %block;
   };
   return(%obj);
}
///////////////////////////////////////////////
function ShootableTarget::onCollision(%this,%obj,%collider)
{
	%obj.playThread(0,"Spin");////REF: Play Target fall animation
        warn("Target Hit!!!");
        %obj.schedule(5000, "playThread", 0, "Reset");////REF: Play Target Reset animation, so we can shoot it again
	warn("Target Resetting...");
}
///////////////////////////////////////////////
function ShootableTarget::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
   echo("ShootableTarget::damage() obj=" @ %obj @ ", source=" @ %sourceObject @ ", damage=" @ %damage);
}
///////////////////////////////////////////////
function ShootableTarget::onDamage(%this, %obj, %delta)
{
   echo("ShootableTarget::onDamage() obj=" @ %obj @ ",delta=" @ %delta);
}
///////////////////////////////////////////////
datablock DebrisData(ShootableTargetDebris)
{
   // Display
   textureName = -1;
//   shapeName = -1;
   render2D = false;

   // Emitters if you wish
   //emitters[0] = DebrisSmokeEmitter;
   //emitters[1] = DebrisFireEmitter;
   //explosion = DebrisExplosion;

   // Physical Properties
   elasticity = 0.20;      // must be between -10.0 and 10.0
   friction = 0.5;         // must be between -10.0 and 10.0
   numBounces = 10;        // must be between 0 and 10000
   bounceVariance = 0;     // must be between 0 and numBounces
   minSpinSpeed = 60;      // must be between -10000.0 and maxSpinSpeed
   maxSpinSpeed = 600;     // must be between -10000.0 and 10000.0
   gravModifier = 1.0;
   terminalVelocity = 0.0;
   velocity = 8.0;
   velocityVariance = 2.5; // must be less then velocity
   lifetime = 30.0;        // must be between 0.0 and 1000.0
   lifetimeVariance = 0.0; // must be between 0.0 and lifetime
   useRadiusMass = true;
   baseRadius = 0.5;

   // Behavior
   staticOnMaxBounce = false;
   explodeOnMaxBounce = false;
   snapOnMaxBounce = false;
   fade = false;
   ignoreWater = true;
  // shapeFile = "~/data/shapes/Targets/Target.dts";
};
#3
08/26/2008 (9:21 am)
After some R&D, I figured out the animation needs to be called in "ShootableTarget::damage" You were right about the projectile. The reason it wasn't being called was because there was no projectile::onCollision. I guess I must have deleted it while cleaning out unneeded information from the crossbow.cs Thanks again.