Author Topic: My sword is firing the projectile from the sword, rather than my camera  (Read 1310 times)

I made a sword add-on that would fire an extra projectile every second. that works fine, but the only problem is that now my sword fires the slash projectiles from the sword too, making it extremely inacurate.


Code: [Select]
   // 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 = false;
Code: [Select]
function SuperswordImage::onFire(%this,%obj,%slot)
{
if(!%obj.lastSuperSword)
{
%obj.lastSuperSword = getSimTime();
}
%spread = 00;
%vector = %obj.getMuzzleVector(%slot);
%vector = VectorScale(%vector, 35);
%x = (getRandom() - 0.5) * %spread;
%y = (getRandom() - 0.5) * %spread;
%z = (getRandom() - 0.5) * %spread;
%mat = MatrixCreateFromEuler(%x SPC %y SPC %z);
%velocity = MatrixMulVector(%mat, %vector);
%p = new projectile()
{
dataBlock = SuperswordProjectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
if((%obj.lastSuperSword + 1000) <= getSimTime())
{
%obj.lastSuperSword = getSimTime();
new projectile()
{
dataBlock = SuperswordSwordProjectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
}
MissionCleanup.add(%p);
return %p;
}

I know how to change where the initial position of the projectile is, but i dont know how to change it to the eye.

The normal variable to make it shoot from the eye is irrelevant since you've overwritten onFire. Use getEyePoint instead of getMuzzlePoint when creating the projectile in yours. Be sure to remove the slot argument since the eyePoint doesn't use it. Also you'll want getEyeVector instead of getMuzzleVector near the start; same deal with the argument.

After doing that, it just wont fire any projectiles at all. i might have done something wrong, but i dont think i did.
Edit : I'm getting an error saying "Player::getEyePoint - wrong number of arguments."
Code: [Select]
function SuperswordImage::onFire(%this,%obj,%slot)
{
if(!%obj.lastSuperSword)
{
%obj.lastSuperSword = getSimTime();
}
%spread = 00;
%vector = %obj.getEyeVector(%slot);
%vector = VectorScale(%vector, 35);
%x = (getRandom() - 0.5) * %spread;
%y = (getRandom() - 0.5) * %spread;
%z = (getRandom() - 0.5) * %spread;
%mat = MatrixCreateFromEuler(%x SPC %y SPC %z);
%velocity = MatrixMulVector(%mat, %vector);
%p = new projectile()
{
dataBlock = SuperswordProjectile;
initialVelocity = %velocity;
initialPosition = %obj.getEyePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
if((%obj.lastSuperSword + 1000) <= getSimTime())
{
%obj.lastSuperSword = getSimTime();
new projectile()
{
dataBlock = SuperswordSwordProjectile;
initialVelocity = %velocity;
initialPosition = %obj.getEyePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
}
MissionCleanup.add(%p);
return %p;
}
« Last Edit: January 08, 2015, 02:05:45 PM by blobo »

After doing that, it just wont fire any projectiles at all. i might have done something wrong, but i dont think i did.

Change
      
%vector = %obj.getEyeVector(%slot);

initialPosition = %obj.getEyePoint(%slot);

to
      
%vector = %obj.getEyeVector();

initialPosition = %obj.getEyePoint();

Be sure to remove the slot argument since the eyePoint doesn't use it.
You should read a bit more carefully, Blobo.

Thanks! it works perfectly!
 
You should read a bit more carefully, Blobo.

indeed i do.