Game Development Community

Have a static shape fire a projectile

by Dennis in 3D · in Technical Issues · 07/12/2008 (10:39 am) · 9 replies

I would like to know what i need to do to have a a statue (static object) spew a fireball from it's mouth. Can anyone point me in the right direction.

#1
07/12/2008 (11:01 am)
You probably want to do it with particles, not a projectile. From what I can tell, a projectile must be shot out of a weapon, or some other similar shapeBase object.
#2
07/12/2008 (1:52 pm)
This is something that really isn't that hard to do. You can attach your bolt emitter to any object you can model. Here is the code I modified to shoot a 3 colored projectile into the air. i added a transperant collision plane in the air above it to give a nice little fireworks display. You are welcome to use it, just don't remove the copywrites at the top. It's a modified fireblocks code from Ed Maurinas awesome first book.

//------------------------------------------------------
// Copyright 2000-2005, GarageGames.com, Inc.
// Written, modfied, or otherwise interpreted by Ed Maurina, Hall Of Worlds, LLC
// Modified again by Mike Rowley, http://3dcentral.net
//------------------------------------------------------
//
//  Sound datablocks
//
datablock AudioProfile(BulletFireSound)
{
filename = "~/data/sound/rocket";
description = AudioDefault3d;
preload = true;
};
datablock AudioProfile(BulletExplosionSound)
{
filename = "~/data/sound/explosion_mono_01";
description = AudioDefault3d;
preload = true;
};
// *********************** SMOKE PARTICLES
//
datablock ParticleData(baseSmokePD0)
{
	animateTexture			= false;
   textureName          = "~/data/shapes/particles/smoke";
	constantAcceleration	= 0.0;
	dragCoefficient			= 0.1;
	windCoefficient			= 0.0;
	gravityCoefficient		= -0.1;
	inheritedVelFactor		= 1.0;
	lifetimeMS				= 2500;
	lifetimeVarianceMS		= 500;
    spinRandomMin			= 0.0;
	spinRandomMax			= 0.0;
	spinSpeed				= 0.0;
	times[0]				= 0.0;
	times[1]				= 0.33;
	times[2]				= 0.66;
	times[3]				= 1.0;
	colors[0]				= "1.0 1.0 1.0 1.0";
	colors[1]				= "1.0 1.0 1.0 0.7";
	colors[2]				= "1.0 1.0 1.0 0.1";
	colors[3]				= "1.0 1.0 1.0 0.05";
	sizes[0]				= 1.0;
	sizes[1]				= 1.0;
	sizes[2]				= 1.0;
	sizes[3]				= 1.0;
	useInvAlpha				= false;

};
//-------------------------------------------------------------------------
//             FireBallParticle Datablock Definition
//-------------------------------------------------------------------------
datablock ParticleData(FireBallParticle : baseSmokePD0 )
{
   dragCoeffiecient     = 0.0;
   gravityCoefficient   = 0.0;
   inheritedVelFactor   = 0.0;
   lifetimeMS           = 350;
   lifetimeVarianceMS   = 50;
   spinRandomMin = -30.0;
   spinRandomMax = 30.0;
   colors[0]     = "0.9 0.6 0.2 0.1";
   colors[1]     = "0.9 0.7 0.1 0.1";
   colors[2]     = "0.9 0.7 0.1 0.1";
   sizes[0]      = 0.5;
   sizes[1]      = 0.7;
   sizes[2]      = 1.0;
   times[0]      = 0.0;
   times[1]      = 0.3;
   times[2]      = 1.0;
};

//-------------------------------------------------------------------------
//             FireBallEmitter Datablock Definition
//-------------------------------------------------------------------------
datablock ParticleEmitterData(FireBallEmitter)
{
   ejectionPeriodMS = 20;
   periodVarianceMS = 5;
   ejectionVelocity = 0.25;
   velocityVariance = 0.10;
   thetaMin         = 0.0;
   thetaMax         = 180.0;  
   particles = FireBallParticle;
};


//-------------------------------------------------------------------------
//  My Fireworks           FireBallExplosionParticle Datablock Definition
//-------------------------------------------------------------------------
datablock ParticleData(FireBallExplosionParticle0 )
{
	animateTexture			= false;
    textureName          = "~/data/shapes/particles/red";
	constantAcceleration	= 0.0;
	dragCoefficient			= 0.1;
	windCoefficient			= 0.0;
	gravityCoefficient		= -0.1;
	inheritedVelFactor		= 1.0;
	lifetimeMS				= 2500;
	lifetimeVarianceMS		= 500;
    spinRandomMin			= 0.0;
	spinRandomMax			= 0.0;
	spinSpeed				= 0.0;
	times[0]				= 0.0;
	times[1]				= 0.33;
	times[2]				= 0.66;
	times[3]				= 1.0;
	colors[0]				= "1.0 1.0 1.0 1.0";
	colors[1]				= "1.0 1.0 1.0 0.7";
	colors[2]				= "1.0 1.0 1.0 0.1";
	colors[3]				= "1.0 1.0 1.0 0.05";
	sizes[0]				= 1.0;
	sizes[1]				= 1.0;
	sizes[2]				= 1.0;
	sizes[3]				= 1.0;
	useInvAlpha				= false;
};
datablock ParticleData(FireBallExplosionParticle1 : FireBallExplosionParticle0 )
{
   textureName          = "~/data/shapes/particles/gold";
};
datablock ParticleData(FireBallExplosionParticle2 : FireBallExplosionParticle0 )
{
   textureName          = "~/data/shapes/particles/green";
};
datablock ParticleData(FireBallExplosionParticle3 : FireBallExplosionParticle0 )
{
   textureName          = "~/data/shapes/particles/blue";
};

Darn max words censor. See the next post for the rest of it.
#3
07/12/2008 (1:52 pm)
Continued from above:

//-------------------------------------------------------------------------
//             FireBallExplosionEmitter Datablock Definition
//-------------------------------------------------------------------------
datablock ParticleEmitterData(FireBallExplosionEmitter)
{
   ejectionPeriodMS = 200;
   periodVarianceMS = 100;
   ejectionVelocity = 2; //1
   velocityVariance = 0.50;
   ejectionOffset   = 2.0;
   thetaMin         = 0;
   thetaMax         = 60;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   particles = "FireBallExplosionParticle0  FireBallExplosionParticle1  FireBallExplosionParticle2  FireBallExplosionParticle3";
};


//-------------------------------------------------------------------------
//             FireBallExplosion Datablock Definition
//-------------------------------------------------------------------------
datablock ExplosionData(FireBallExplosion)
{
   soundProfile = BulletExplosionSound;
   lifeTimeMS = 2000;
   particleEmitter = FireBallExplosionEmitter;
   particleDensity = 25;
   particleRadius = 2.0;
   faceViewer     = true;

   // Dynamic light
//   lightStartRadius = 0;
//   lightEndRadius   = 6;
//   lightStartColor  = "1 0.2 1";
//   lightEndColor    = "1 0.6 0.2";
};

//-------------------------------------------------------------------------
//             FireBallProjectile Datablock Definition
//-------------------------------------------------------------------------
datablock ProjectileData(FireBallProjectile)
{
   projectileShapeName = "~/data/shapes/projectile/projectile.dts";

   explosion		    = FireBallExplosion;

   particleEmitter		= FireBallEmitter;

   armingDelay			= 0;

   lifetime				= 5000;
   fadeDelay			= 4800;

   isBallistic			= false;
};

//-------------------------------------------------------------------------
//             FireBallBlock Datablock Definition
//-------------------------------------------------------------------------
datablock StaticShapeData( FireBallBlock )
{
   category				= "FireBallBlocks";
   shapeFile			= "~/data/shapes/cannon/cannon.dts"; //This is your object you want to fire your projectile from.
   emap					= false;
   isInvincible		    = true;

};
//***********************************************************
// This starts the shooting going.
//************************************************************

  function ShapeBase::ShootIt( %handle ){
       %handle.doFire(true);
       %handle.schedule(9000, ShootIt);
       }
       
// ******************************************************************
//					doFire() 
// ******************************************************************
//
function StaticShape::doFire( %handle ) {

        //echo( "calling Fire 1");
        %handle.shootFireBall( FireBallProjectile , "0 0 1" , 20 );

}


// ******************************************************************
//					shootFireBall() 
// ******************************************************************
//
// 1. Create a projectile and fire in the direction and with velocity requested.
//
function StaticShape::shootFireBall( %marker, %projectile , %pointingVector , %velocity) 
{

    %bullet = new Projectile() {
        dataBlock        = FireBallProjectile; //%projectile;
        initialVelocity  = vectorScale( vectorNormalize(%pointingVector) , %velocity );
        initialPosition  = %marker.getWorldBoxCenter();
        sourceObject     = -1;
        sourceSlot       = -1;
        theMarker        = %marker;
       // stateSound[1]    = BulletFireSound;
    };

    %marker.bullet = %bullet;
    MissionCleanup.add(%bullet);
}
// ******************************************************************
//					FireBallProjectile::onCollision() 
// ******************************************************************
function FireBallProjectile::onCollision( %projectileDB , %projectileObj , %collidedObj, %fade, %vec, %speed) 
{
   if (!$Game::Running) return;
//   echo("onCollision( ", %projectileDB ," , ",%projectileObj," , ",%collidedObj," , ",%fade," , ",%vec," , ",%speed," )");
    // sfxPlay(CrossbowExplosionSound);
//   echo(%collidedObj.getClassName());
   
//   if (%collidedObj.getClassName() $= "Player")
//   {
 //     %collidedObj.loseALife();
 // ***** add cannon delete and scedule it to be replaced here. *****
//   }
 }
#4
07/12/2008 (2:23 pm)
Thanks, I am sure this will do it. I appreciate all your help:0)
#5
07/13/2008 (2:46 pm)
Thx again I finally got the code compiling with no errors but how do I get the fire ball to shoot? Do I place it in a trigger? If so do I have to create a sim set?
#6
07/13/2008 (4:19 pm)
You can put it in a trigger if you want. To call it,
Just call:

name of cannon.ShootIt();

I had mine shooting fireworks (what that code was used for) constantly once the game started so I put Cannon1.ShootIt(); in server/scripts/game.cs in function startGame()

If you don't want that code to constantly shoot at regular intervals, you will want to remove the scedule.
#7
07/14/2008 (8:03 pm)
It Worked Thx :0)
#8
07/15/2008 (4:34 pm)
Yer welcome. :)
#9
04/09/2009 (1:02 am)
Well i got another problem very similar to this :/ i would like the projectile to shoot where you are looking. In the provided codes it only shoots upward :/ and in addition my projectile doesn't eject particles :/