Dual muzzlepoints?
by Scott Doherty - A.K.A. Jetsum · in Game Design and Creative Issues · 11/13/2009 (10:07 am) · 3 replies
I'm working on a game where the player/mech has a dual cannon. however I can't seem to to get the coded muzzel flash/partical on the second cannon. I have the DTS setup with a muzzlepoint node but was wondering if there was a way to clone that muzzelpoint so the flash happens on both cannons or does it have to be done in the code and set to a second muzzlepoint node. was also wondering if it would be just as easy to IFL for the the muzzle flash. I am working with 3ds max 2009 for the model and TGE 1.5 for the engine. any help would be of great help.
About the author
Recent Threads
#2
01/19/2010 (9:30 pm)
You may find this useful...function ChaingunImage::onFire(%data,%obj,%slot)
{
Parent::onFire(%data,%obj,%slot);
%obj.nextWeaponFire = 2;
schedule(%data.fireTimeout, 0, "fireNextGun", %obj);
}
function Chaingun2Image::onFire(%data,%obj,%slot)
{
Parent::onFire(%data,%obj,%slot);
%obj.nextWeaponFire = 0;
schedule(%data.fireTimeout, 0, "fireNextGun", %obj);
}
function ChaingunImage::onTriggerDown(%this, %obj, %slot)
{
}
function ChaingunImage::onTriggerUp(%this, %obj, %slot)
{
}
function fireNextGun(%obj)
{
if(%obj.fireWeapon)
{
if(%obj.nextWeaponFire == 0)
{
%obj.setImageTrigger(2, true);
%obj.setImageTrigger(3, true);//false
}
else
{
%obj.setImageTrigger(2, true);//false
%obj.setImageTrigger(3, true);
}
}
else
{
%obj.setImageTrigger(2, false);
%obj.setImageTrigger(3, false);
}
}
#3
Some of this is overkill, you can use a more basic onFire function if you want.
01/19/2010 (9:31 pm)
And here is the part that make em go bang. ;)Some of this is overkill, you can use a more basic onFire function if you want.
function ShapeBaseImageData::onFire(%this, %obj, %slot)
{
%projectile = %this.projectile;
// Decrement inventory ammo. The image's ammo state is update
// automatically by the ammo inventory hooks.
%obj.decInventory(%this.ammo,1);
// Get the weapons projectile spread and ensure it is never 0
// (we need some spread direction even if it is extremely tiny)
%spread = %this.projectileSpread;
%spread = %spread $= "" ? 0.001 : %spread;
%spread = %spread <= 0 ? 0.001 : %spread;
// Determine if we are using a shotgun class weapon or not
// If we are using a shotgun, set the number of projectiles we are going to fire to 12
%shellcount = 1;
if(%this.isShotGun) //if(%projectile.isShotGun)
%shellcount = 12;
// Create each projectile and send it on its way
for(%shell=0; %shell<%shellcount; %shell++)
// Get the muzzle vector. This is the dead straight aiming point of the gun
%vector = %obj.getMuzzleVector(%slot);
// Get our players velocity. We must ensure that the players velocity is added
// onto the projectile
%objectVelocity = %obj.getVelocity();
// Determine scaled projectile vector. This is still in a straight line as
// per the default example
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
// Determine our random x, y and z points in our spread circle and create
// a spread matrix.
%x = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
// Alter our projectile vector with our spread matrix
%velocity = MatrixMulVector(%mat, %velocity);
// Create our projectile
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
Torque Owner Inflight
Default Studio Name
Imagine, two chainguns mounted to the doors of a car.
Note the mount points. ;)
Left hand side of car.
datablock ShapeBaseImageData(ChaingunImage) //LHS OF CAR { className = "WeaponImage"; shapeFile = "~/data/shapes/chaingun/weapon_chaingun2.dts"; mountPoint = 2; item = Chaingun; ammo = ChaingunAmmo; projectile = ChaingunBullet; projectileType = Projectile; emap = true; casing = ShellDebris; shellExitDir = "-1.0 0.3 1.0";//"1.0 0.3 1.0"; shellExitOffset = "0.15 -0.56 -0.1";//"0.15 -0.56 -0.1"; shellExitVariance = 15.0; shellVelocity = 3.0; correctMuzzleVector = true; projectileSpread = 8.0 / 1000.0; isShotGun = false; lightType = "WeaponFireLight" ; lightColor = "0.25 0.20 0.0 1.0" ; lightTime = "200" ; lightRadius = "1.5" ; //-------------------------------------- stateName[0] = "Activate"; stateSequence[0] = "Activate"; stateSound[0] = ChaingunSwitchSound; stateAllowImageChange[0] = false; // stateTimeoutValue[0] = 0.5; {...} };right hand side of car.
datablock ShapeBaseImageData(Chaingun2Image)//RHS OF CAR { className = "WeaponImage"; shapeFile = "~/data/shapes/chaingun/weapon_chaingun.dts"; mountPoint = 3; item = Chaingun; ammo = ChaingunAmmo; projectile = ChaingunBullet; projectileType = Projectile; emap = true; casing = ShellDebris; shellExitDir = "1.0 0.3 1.0"; shellExitOffset = "0.15 -0.56 -0.1"; shellExitVariance = 15.0; shellVelocity = 3.0; correctMuzzleVector = true; projectileSpread = 8.0 / 1000.0; isShotGun = false; lightType = "WeaponFireLight" ; lightColor = "0.25 0.20 0.0 1.0" ; lightTime = "200" ; lightRadius = "1.5" ; //-------------------------------------- stateName[0] = "Activate"; stateSequence[0] = "Activate"; stateSound[0] = ChaingunSwitchSound; stateAllowImageChange[0] = false; {...} );