Game Development Community

Collision damage with .difs

by Ronald J Nelson · in Torque Game Engine · 03/16/2007 (1:25 am) · 3 replies

I am using .dif objects for my barriers and a ton of other things for my game and really want the vehicles to be able to take damage if they crash into them at high speeds. The problem is that the shapebase oncollision doesn't recognize the collision with .difs.

Is there someway to enable this?

#1
03/16/2007 (1:32 am)
There's an onImpact callback for ShapeBaseData objects which handles just your type of collisions. There are also a lot of related properties in the datablock. You might want to have a look at it.

--Amr
#2
03/16/2007 (1:54 am)
What Amr said...

Here's an example of what you might need:

datablock WheeledVehicleData(Ron's Vehicle)
{
   maxDamage                = 500;
   destroyedLevel           = 490;

   minImpactSpeed           = 5;           // Impacts over this invoke the script callback
   softImpactSpeed          = 5;           // Play SoftImpact Sound
   hardImpactSpeed          = 15;          // Play HardImpact Sound

   softImpactSound          = SoftImpactSound;
   hardImpactSound          = HardImpactSound;
   wheelImpactSound         = WheelImpactSound;

   // Damage emitters, explosions and debris
   damageEmitter[0]         = LightDamageSmoke;
   damageEmitter[1]         = HeavyDamageSmoke;

   damageEmitterOffset[0]   = "0 2.5 -0.5";
   damageEmitterOffset[1]   = "0 2 -2";

   damageLevelTolerance[0]  = 0.3;
   damageLevelTolerance[1]  = 0.7;

   numDmgEmitterAreas       = 2;

   explosion                = GenericLargeExplosion;

   debrisShapeName          = "your debris path here";
   debris = ShapeDebris;

   renderWhenDestroyed      = false;
};

function WheeledVehicleData::onDamage(%this,%obj)
{
   %damageAmt = %obj.getDamageLevel();

   if (%damageAmt >= %this.destroyedLevel)
   {
         %obj.setDamageState(Destroyed);
   }
}

function WheeledVehicleData::damage(%data, %obj, %sourceObj, %position, %amount, %damageType, %momentum)
{
   %obj.applyDamage(%amount);
}

function WheeledVehicleData::onImpact(%data, %obj, %col, %vec, %speed)
{
   %obj.damage(%obj,%pos,( 2 * %speed ), "VehicleImpact");
}

function WheeledVehicleData::onDestroyed(%data, %obj, %prevState)
{
   // Create our explosion damage
   %damage  = 1000;
   %radius  = 10;
   %impulse = 10;
   %dmgType = "car damage";

   radiusDamage(%obj, %obj.getPosition(), %radius, %damage, %dmgType, %impulse);

   // Delete the destroyed vehicle
   %obj.schedule(100, "delete");
}
#3
03/16/2007 (1:59 am)
See this is why I am glad I went with this engine, the community rocks. Thanks for the really quick response guys.