TGB/MiniTutorials/ExplodingObjects

From TDN

Back

Exploding Objects with Particle Explosions
Description:

This sample script will load an explosion particle effect upon your object's collision.

This detail uses the onCollision callback when the ship collides with the asteroid. It then loads in a particle effect, positions it, sets it to be destroyed in one second, and then plays the effect. The final step is to safeDelete() the ship that way it is removed.

Image:ExplosionPic.JPG


 Download Files :

Exploding Ship Files




The explosion effect loaded is in the TGB project and be sure to set both your object you want to explode and the object you want to explode against up for collision (send/receive). Also be sure to set your object to explode to do a collision callback. Then give that object the class (ExplodingShip) and give it a velocity to move towards the object to explode against.

function ExplodingShip::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
   // create a new particle effect
   %eff = new t2dParticleEffect() { scenegraph = %srcObj.scenegraph; };
   
   // load in our shockwave explosion and set its position to our source object's position
   %eff.loadEffect("~/data/particles/shockwave_burst.eff");
   %eff.setPosition(%srcObj.getPosition());
   %eff.playEffect();
   
   // delete our exploding object
   %srcObj.safeDelete();
}


Back