Author Topic: Bullets wont fire straight ahead  (Read 731 times)

I want to mak it so my gun will shoot 8 projectiles in a horisontal line when charged and fired, it shoots horisantally but all the bullets fire to the right of my screen instead of straight. What have i done wrong?

Code: [Select]
function wcbImage::onchargeFire(%this,%obj,%slot)
{
if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
return;
%obj.lastFireTime = getSimTime();
     
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));
%obj.playThread(2, shiftAway);

%projectile = %this.projectile;
%spread = 0.0025;
%shellcount = 8;

for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 1.0) * 20 * 5 * %spread;
%y = (getRandom() - 0.0) * 0 * 0 * %spread;
%z = (getRandom() - 0.0) * 0 * 0 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}

Code: [Select]
%spread = 0.0025;Make it:
Code: [Select]
%spread = 0.0000;

Change this
Code: [Select]
%x = (getRandom() - 1.0) * 20 * 5 * %spread;to either
Code: [Select]
%x = (getRandom() - 2.0) * 20 * 5 * %spread;for a random pattern, or
Code: [Select]
%x = (%i - 4) * 25 * %spread;for a predictable horizontal spread.

with the 1st it shoots horisontally for some reason and with the second one it doesnt even spread out

with the 1st it shoots horisontally for some reason and with the second one it doesnt even spread out
You wanted it to shoot horizontally?

Try this:
Code: [Select]
%x = (%shell - 4) * 25 * %spread;

You wanted it to shoot horizontally?

Try this:
Code: [Select]
%x = (%shell - 4) * 25 * %spread;
they now shoot in a slanted line, could this be because of the get random for y and z

Post your current code.

Code: [Select]
//wcb.cs

//audio
datablock AudioProfile(wcbShot1Sound)
{
   filename    = "./wcbShot1Sound.wav";
   description = AudioClose3d;
   preload = true;
};
datablock AudioProfile(wcbShot2Sound)
{
   filename    = "./wcbShot2Sound.wav";
   description = AudioClose3d;
   preload = true;
};
datablock AudioProfile(wcbhitSound)
{
   filename    = "./wcbhit.wav";
   description = AudioClose3d;
   preload = true;
};
datablock AudioProfile(wcbchargeSound)
{
   filename    = "./wcbcharge.wav";
   description = AudioClose3d;
   preload = true;
};

//muzzle flash effects

datablock ParticleData(wcbshotParticle)
{
dragCoefficient      = 3;
gravityCoefficient   = -0.5;
inheritedVelFactor   = 0.2;
constantAcceleration = 0.0;
lifetimeMS           = 525;
lifetimeVarianceMS   = 55;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0]     = "0.0 1.0 0.0 0.9";
colors[1]     = "0.1 1.0 0.1 0.0";
sizes[0]      = 0.25;
sizes[1]      = 0.25;

useInvAlpha = false;
};

datablock ParticleEmitterData(wcbshotEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 1.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 50;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "wcbshotParticle";

   uiName = "LEGO Bowcaster Shot";
};

datablock ParticleData(wcbchargedParticle)
{
dragCoefficient      = 3;
gravityCoefficient   = 0.0;
inheritedVelFactor   = 0.2;
constantAcceleration = 0.0;
lifetimeMS           = 200;
lifetimeVarianceMS   = 55;
textureName          = "base/data/particles/star1";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0]     = "0.0 1.0 0.0 0.9";
colors[1]     = "0.1 1.0 0.1 0.0";
sizes[0]      = 0.40;
sizes[1]      = 0.40;

useInvAlpha = false;
};

datablock ParticleEmitterData(wcbchargedEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 0.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 50;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "wcbchargedParticle";

   uiName = "LEGO Bowcaster Charged";
};

datablock ParticleData(wcbTrailparticle)
{
dragCoefficient      = 3;
gravityCoefficient   = 0.0;
inheritedVelFactor   = 0.0;
constantAcceleration = 0.0;
lifetimeMS           = 75;
lifetimeVarianceMS   = 55;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -50.0;
spinRandomMax = 50.0;
colors[0]     = "0.0 1.0 0.0 0.5";
colors[1]     = "0.1 1.0 0.1 0.5";
sizes[0]      = 0.25;
sizes[1]      = 0.25;
//times[0] = 0.5;
//times[1] = 0.5;

useInvAlpha = true;
};

datablock ParticleEmitterData(wcbTrailEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 0.0; //0.25
   velocityVariance = 0.0; //0.10
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "wcbTrailparticle";

   useEmitterColors = true;
   uiName = "LEGO Bowcaster Trail";
};

datablock ParticleData(wcbExplosionParticle)
{
dragCoefficient      = 8;
gravityCoefficient   = 1;
inheritedVelFactor   = 0.2;
constantAcceleration = 0.0;
lifetimeMS           = 700;
lifetimeVarianceMS   = 400;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -50.0;
spinRandomMax = 50.0;
colors[0]     = "0.0 1.0 0.0 0.5";
colors[1]     = "0.0 0.9 0.0 0.0";
sizes[0]      = 0.75;
sizes[1]      = 0.85;

useInvAlpha = true;
};

datablock ParticleEmitterData(wcbExplosionEmitter)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 2;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 89;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "wcbExplosionParticle";

   useEmitterColors = true;
   uiName = "LEGO Bowcaster Explosion";
};

datablock ExplosionData(wcbExplosion)
{
   //explosionShape = "";
soundProfile = wcbhitSound;

   lifeTimeMS = 150;

   particleEmitter = wcbExplosionEmitter;
   particleDensity = 5;
   particleRadius = 0.2;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = false;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;

   // Dynamic light
   lightStartRadius = 0;
   lightEndRadius = 4;
   lightStartColor = "0.0 0.9 0.0 1.0";
   lightEndColor = "0.0 1.0 0.0 1.0";
};


AddDamageType("wcb",   '<bitmap:add-ons/Pack_LEGOweapons/CI_wcb> %1',    '%2 <bitmap:add-ons/Pack_LEGOweapons/CI_wcb> %1',0.2,1);
datablock ProjectileData(wcbProjectile)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 40;
   directDamageType    = $DamageType::wcb;
   radiusDamageType    = $DamageType::wcb;

   brickExplosionRadius = 0;
   brickExplosionImpact = true;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 10;
   brickExplosionMaxVolume = 1;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 2;  //max volume of bricks that we can destroy if they aren't connected to the ground

   impactImpulse      = 250;
   verticalImpulse   = 200;
   explosion           = wcbExplosion;
   particleEmitter     = wcbTrailEmitter;

   muzzleVelocity      = 80;
   velInheritFactor    = 1;

   armingDelay         = 00;
   lifetime            = 4000;
   fadeDelay           = 3500;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;
   isBallistic         = false;
   gravityMod = 0.0;

   hasLight    = True;
   lightRadius = 3.0;
   lightColor  = "0.0 1.0 0.0";

   uiName = "Bowcaster Laser";
};

//////////
// item //
//////////
datablock ItemData(wcbItem)
{
category = "Weapon";  // Mission editor category
className = "Weapon"; // For inventory system

// Basic Item Properties
shapeFile = "./wcb.dts";
rotate = false;
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;

//gui stuff
uiName = "LEGO Bowcaster";
iconName = "./icon_wcb";
doColorShift = true;
colorShiftColor = "1.00 1.00 1.00 1.000";

// Dynamic properties defined by the scripts
image = wcbImage;
canDrop = true;
};

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(wcbImage)
{
   // Basic Item properties
   shapeFile = "./wcb.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
   eyeOffset = 0; //"0.7 1.2 -0.5";
   rotation = eulerToMatrix( "0 0 0" );

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off. 
   correctMuzzleVector = true;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = BowItem;
   ammo = " ";
   projectile = wcbProjectile;
   projectileType = Projectile;


   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = true;

   doColorShift = true;
   colorShiftColor = wcbItem.colorShiftColor;//"0.400 0.196 0 1.000";

   //casing = " ";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "chargeopt";
stateAllowImageChange[1]         = true;
stateSequence[1] = "Ready";

stateName[2] = "chargeopt";
stateTransitionOnTriggerUp[2] = "fire";
stateWaitForTimeout[2] = false;
stateTransitionOnTimeout[2] = "chargeready";
stateTimeoutvalue[2] = 3;
stateAllowImageChange[2]        = true;

stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "Reload";
stateTimeoutValue[3]            = 0.1;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;
stateEmitter[3] = wcbshotemitter;
stateEmitterTime[3] = 0.05;
stateEmitterNode[3] = "muzzleNode";
stateSound[3] = wcbShot1Sound;

statename[4] = "Reload";
statesequence[4] = "Reload";
stateTransitionOnTimeout[4] = "Ready";
stateTimeoutValue[4] = 0.3;

statename[5] = "chargeready";
stateTransitionOnTriggerUp[5] = "chargefire";
stateEmitter[5] = wcbchargedEmitter;
stateEmitterTime[5] = 0.3;
stateEmitterNode[5] = "muzzleNode";
stateSound[5] = wcbchargeSound;
stateTransitionOnTimeout[5] = "chargeready";
stateTimeoutValue[5] = 0.3;

statename[6] = "chargefire";
statesequence[6] = "Fire";
stateFire[6] = true;
stateScript[6] = "onchargeFire";
stateTransitiononTimeout[6] = "Reload";
stateEmitter[6] = wcbshotemitter;
stateEmitterTime[6] = 0.05;
stateEmitterNode[6] = "muzzleNode";
stateSound[6] = wcbShot2Sound;

};

function wcbImage::onchargeFire(%this,%obj,%slot)
{
if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
return;
%obj.lastFireTime = getSimTime();
     
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));

%projectile = %this.projectile;
%spread = 0.0050;
%shellcount = 8;

for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (%shell - 4) * 25 * %spread;
%y = (getRandom() - 0.0) * 0 * 0 * %spread;
%z = (getRandom() - 0.0) * 0 * 0 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}

Lego bowcaster shot?