Author Topic: How to spawn explosion?  (Read 1234 times)

I looked at the tank and that's how I got the code, but it only shows the explosion light D:

You need all of the arguments it has, or your projectile won't actually do anything even if it does explode.
Quote
%scaleFactor = getWord(%mount.getScale(), 2); //Change %mount to be the user.
%p = new Projectile()
{
 dataBlock = tankShellProjectile; //Change this to your projectile datablock
 initialPosition = vectorAdd(%mount.getEyeTransform(),vectorScale(%mount.getEyeVector(),3)); //Change this to the user's muzzle point
 initialVelocity = vectorScale(%mount.getEyeVector(),140 * %scaleFactor); //Change this to the user's muzzle vector so the explosion shows the right way when it explodes
 sourceObject = %obj;  //Change this to the user
 client = %obj.client; //Change this to the user's client
 sourceSlot = 0;       //Keep this
 originPoint = vectorAdd(%mount.getEyeTransform(),vectorScale(%mount.getEyeVector(),3)); //Change it to the same as initialPosition
};
MissionCleanup.add(%p);
%p.setScale(%scaleFactor SPC %scaleFactor SPC %scaleFactor);
//Then do %p.explode();

Here's the code that I have now:
Code: [Select]
function TNTImage::onPreFire(%c)
{
%mount = %c.getObjectMount();
%scaleFactor = getWord(%mount.getScale(), 2); //Change %mount to be the user.
%p = new Projectile()
{
 dataBlock = TNTProjectile; //Change this to your projectile datablock
 initialPosition = vectorAdd(%mount.getEyeTransform(),vectorScale(%mount.getEyeVector(),3)); //Change this to the user's muzzle point
 initialVelocity = vectorScale(%mount.getEyeVector(),140); //Change this to the user's muzzle vector so the explosion shows the right way when it explodes
 sourceObject = %mount;  //Change this to the user
 client = %mount.client; //Change this to the user's client
 sourceSlot = 0;       //Keep this
 originPoint = vectorAdd(%mount.getEyeTransform(),vectorScale(%mount.getEyeVector(),3)); //Change it to the same as initialPosition
};
MissionCleanup.add(%p);
%p.setScale(%scaleFactor SPC %scaleFactor SPC %scaleFactor);
%p.explode();
}

Did I implement this correctly?  It's still only show's the light from the explosion D=

The arguments for ::onPreFire are wrong, and you didn't change any of the things I said apart from the projectile. %mount does not exist there, that was only for the Tank code.