Enhanced Projectiles Mod: Speed Based Projectile Spread
by CSMP · 08/05/2009 (9:00 pm) · 3 comments
You will need to have Ron Nelson's Enhanced Projectile Resource already installed to use this modification.
www.garagegames.com/community/resources/view/14044/3#comment-133847
First off, I have multiple positions and each position has differant speeds, therefore moving while standing will create the most spread, moving while crouching will create less spread, moving while prone creates even less spread and finally not moving at all creates the least amount of spread.
Either way there are 3 speeds (and stationary) in which your projectile will alter its own spread, you will most likely need to adjust the velocity in which the spread changes and the spread itself (depending on the weapon used obviously).
Replace the stock Enhanced Projectile MP5::onFire Function with this and modify to your specific weapon's needs.
I just figured this it out and thought it would help others... while promoting advanced weaponry with TGE! :)
Created and Tested on TGE1.5.2
www.garagegames.com/community/resources/view/14044/3#comment-133847
First off, I have multiple positions and each position has differant speeds, therefore moving while standing will create the most spread, moving while crouching will create less spread, moving while prone creates even less spread and finally not moving at all creates the least amount of spread.
Either way there are 3 speeds (and stationary) in which your projectile will alter its own spread, you will most likely need to adjust the velocity in which the spread changes and the spread itself (depending on the weapon used obviously).
Replace the stock Enhanced Projectile MP5::onFire Function with this and modify to your specific weapon's needs.
function MP5Image::onFire(%this, %obj, %slot)
{
// Decrease the weapons ammo on fire
%obj.decInventory(%this.ammo,1);
// Get the type of projectile we are gonna fire
%projectile = %this.projectile;
//To have a basic spread working, remove everything EXCEPT the Stationary Spread Code below
if( VectorLen(%obj.getVelocity()) > 3 ) //Standing Move Speed
%SpeedSpread = (8.0 / 1000); //Standing Move Projectile Spread
else if ( VectorLen(%obj.getVelocity()) > 0.9 ) //Crouching Move Speed
%SpeedSpread = (6.0 / 1000); //Crouching Move Projectile Spread
else if ( VectorLen(%obj.getVelocity()) > 0.1 ) //Prone Move Speed
%SpeedSpread = (4.0 / 1000); //Prone Move Projectile Spread
else
%SpeedSpread = (2.0 / 1000); //Stationary Projectile Spread...
// Get the weapons projectile spread and ensure it is never 0
// (we need some spread direction even if it is extremely tiny)
%spread = %SpeedSpread;
%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)
%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;
isArmorPiercing = true;
wrappedDecalsMode = false;
};
MissionCleanup.add(%p);
}
return %p;
}I just figured this it out and thought it would help others... while promoting advanced weaponry with TGE! :)
Created and Tested on TGE1.5.2
About the author
#2
I'd imagine:
1. Set a low projectile LifeTime (and FadeDelay?) on the FlameBullets
2. Probably turn the isShotgun variable ON
3. Set a higher projectile spread value
4. Set up a particle emitter on the FlameThrower weapon
That should work as a crude flamethrower.
08/05/2009 (11:21 pm)
Sure, with little modification I believe.I'd imagine:
1. Set a low projectile LifeTime (and FadeDelay?) on the FlameBullets
2. Probably turn the isShotgun variable ON
3. Set a higher projectile spread value
4. Set up a particle emitter on the FlameThrower weapon
That should work as a crude flamethrower.
#3
08/06/2009 (9:21 am)
Well this is a pretty cool addition. Nice job. 
Torque Owner Javier Canon