Game Development Community

Grenade Launcher not working

by Ero "Super Newbie" Sennin · in Torque Game Engine · 03/15/2004 (3:55 pm) · 6 replies

I'm messing around and trying to create a grenade launcher but i'm running into some problems. I'm using a pre-made rocket launcher dts from an example i know hat works and fires.

the problem is i get the dts to mount to the player the click the mouse ad it fires...but nothing comes out all the paths are correct anyone see apro blem with this?

#1
03/15/2004 (3:59 pm)
Datablock AudioProfile( GrenadeExplosionSound )
{ filename = "~/data/shapes/rocket_launcher/rocket_explosion.ogg";
description = AudioDefault3d;
preload = true;
};
datablock ParticleData( GrenadeExplosionSmokeParticle )
{textureName = "~/data/shapes/grenadelauncher/smoke";
useInvAlpha = true;
dragCoeffiecient = 100.0;
inheritedVelFactor = 0.3;
constantAcceleration = -0.3;
lifetimeMS = 1200;
lifetimeVarianceMS = 300;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
colors[0] = "0.56 0.36 0.26 1.0";
colors[1] = "0.2 0.2 0.2 1.0";
colors[2] = "0.0 0.0 0.0 0.0";
sizes[0] = 4.0;
sizes[1] = 2.5;
sizes[2] = 1.0;
};

datablock ParticleEmitterData( GrenadeExplosionSmokeParticleEmitter )
{
particles = "GrenadeExplosionSmokeParticle";
lifetimeMS = 250;
lifetimeVarianceMS = 0;
ejectionPeriodMS = 10;
periodVarianceMS = 0;
ejectionVelocity = 4;
velocityVariance = 0.5;
};
datablock ParticleData( GrenadeExplosionFlashParticle )
{
textureName = "~/data/shapes/grenadelauncher/flash";
useInvAlpha = false;
dragCoeffiecient = 100.0;
inheritedVelFactor = 0.3;
lifetimeMS = 1200;
lifetimeVarianceMS = 300;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
colors[0] = "0.8 0.4 0.0 0.8";
colors[1] = "0.2 0.0 0.0 0.8";
colors[2] = "0.0 0.0 0.0 0.0";
sizes[0] = 1.5;
sizes[1] = 0.9;
sizes[2] = 0.5;
};

datablock ParticleEmitterData( GrenadeExplosionFlashParticleEmitter )
{
particles = "GrenadeExplosionFlashParticle";
lifetimeMS = 250;
lifetimeVarianceMS = 0;
ejectionPeriodMS = 10;
periodVarianceMS = 0;
ejectionVelocity = 0.8;
velocityVariance = 0.5;
};


datablock ParticleData( GrenadeExplosionSparksParticles )
{
textureName = "~/data/shapes/grenadelauncher/spark";
dragCoefficient = 1;
gravityCoefficient = 0.0;
inheritedVelFactor = 0.2;
constantAcceleration = 0.0;
lifetimeMS = 500;
lifetimeVarianceMS = 350;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
colors[0] = "1.0 0.0 0.0 1.0";
colors[1] = "1.0 1.0 0.0 0.8";
colors[2] = "1.0 1.0 1.0 0.1";
sizes[0] = 0.20;
sizes[1] = 0.15;
sizes[2] = 0.5;
};

datablock ParticleEmitterData( GrenadeExplosionSparksParticleEmitter )
{
particles = "GrenadeExplosionSparksParticles";
lifetimeMS = 150;
lifetimeVarianceMS = 0;
ejectionPeriodMS = 2;
periodVarianceMS = 0;
ejectionVelocity = 30;
velocityVariance = 10;
};
#2
03/15/2004 (4:01 pm)
Datablock ExplosionData( GrenadeExplosion )
{soundProfile = GrenadeExplosionSound;
lifeTimeMS = 1200;
lifetimeVarianceMS = 0;
particleEmitter = GrenadeExplosionFlashParticleEmitter;
particleDensity = 100;
particleRadius = 2;
emitter[0] = GrenadeExplosionSmokeParticleEmitter;
emitter[1] = GrenadeExplosionSparksParticleEmitter;
shakeCamera = true;
camShakeFreq = "10.0 11.0 10.0";
camShakeAmp = "1.0 1.0 1.0";
camShakeDuration = 0.5;
camShakeRadius = 10.0;
lightStartRadius = 6;
lightEndRadius = 3;
lightStartColor = "0.5 0.5 0.0";
lightEndColor = "0.0 0.0 0.0";
};

datablock ParticleData( GrenadeExhaustParticle )
{textureName = "~/data/shapes/grenadelauncher/smoke";
useInvAlpha = false;
lifetimeMS = 2000;
lifetimeVarianceMS = 250;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
colors[0] = "0.8 0.3 0.0 1.0";
colors[1] = "0.1 0.1 0.1 0.7";
colors[2] = "0.1 0.1 0.1 0.0";
sizes[0] = 0.1;
sizes[1] = 0.5;
sizes[2] = 1.0;
};
datablock ParticleEmitterData( GrenadeExhaustParticleEmitter )
{particles = GrenadeExhaustParticle;
ejectionPeriodMS = 5;
periodVarianceMS = 2;
ejectionVelocity = 0.1;
velocityVariance = 0.1;
};
datablock ProjectileData( GrenadeProjectile )
{projectileShapeName = "~/data/shapes/grenade/grenade.dts";
muzzleVelocity = 120;
armingDelay = 0;
lifetime = 5000;
fadeDelay = 5000;
isBallistic = true;
gravityMod = 0.5;
hasLight = true;
lightRadius = 5;
lightColor = "0.5 0.5 0.25";
particleEmitter = GrenadeExhaustParticleEmitter;
explosion = GrenadeExplosion;
directDamage = 20;
radiusDamage = 10;
damageRadius = 1.5;
};
function GrenadeProjectile::onCollision( %this, %obj, %col, %fade, %pos, %normal )
{
echo("GrenadeProjectile::onCollision called!");
}
#3
03/15/2004 (4:01 pm)
Datablock ShapeBaseImageData( GrenadeLauncherImage )
{
shapeFile = "~/data/shapes/rocket_launcher/rocket_launcher.dts";
projectile = GrenadeProjectile;
projectileType = Projectile;
fireTimeout = 0;
emap = true;
correctMuzzleVector = false;
mountPoint = 0;
offset = "0.0 0.0 0.0";
eyeOffset = "0.0 0.0 0.0";
stateName[0] = "Preactivate";
stateTransitionOnLoaded[0] = "Activate";
stateTransitionOnNoAmmo[0] = "NoAmmo";
stateName[1] = "Activate";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.5;
stateSequence[1] = "Activate";
stateName[2] = "Ready";
stateTransitionOnNoAmmo[2] = "NoAmmo";
stateTransitionOnTriggerDown[2] = "Fire";
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Reload";
stateTimeoutValue[3] = 0.1;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateEmitterTime[3] = 0.3;
stateName[4] = "Reload";
stateTransitionOnNoAmmo[4] = "NoAmmo";
stateTransitionOnTimeout[4] = "Ready";
stateTimeoutValue[4] = 0.1;
stateAllowImageChange[4] = false;
stateSequence[4] = "Reload";
stateEjectShell[4] = true;
stateName[5] = "NoAmmo";
stateTransitionOnAmmo[5] = "Reload";
stateSequence[5] = "NoAmmo";
stateTransitionOnTriggerDown[5] = "DryFire";
stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";
};
function RocketLauncherImage::onFire( %this, %obj, %slot )
{
%projectile = %this.projectile;
%muzzleVector = %obj.getMuzzleVector( %slot );
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd( VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor) );
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add( %p );
return %p;
}
#4
03/15/2004 (4:02 pm)
Sorry about he long pos also anyone wanna gimme some pointers on normal grenade behavior that'd be awsome
#5
03/15/2004 (4:08 pm)
Join the www.gamebeavers.org site, and gain access to 2 types of grenade launchers, both working excellently.
#6
02/28/2007 (10:52 am)
I know this is a really old post but I will point out the problem anyway. A lot of people miss this little detail and causes them all kinds of grief.

Based on the code above the image name for onFire should be GrenadeLauncherImage. 
Thats why it will not fire. Change RocketLauncherImage to GrenadeLauncherImage and it should work.

function RocketLauncherImage::onFire( %this, %obj, %slot )
{
%projectile = %this.projectile;
%muzzleVector = %obj.getMuzzleVector( %slot );
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd( VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor) );
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add( %p );
return %p;
}