Author Topic: Projectile Velocity (Math) Issue  (Read 615 times)

This is what I have, I'm trying to get ::onTrigger to fire a different projectile upon trigger 4, but the projectile only goes to the right place when %obj has velocity for some reason: (it's in a package already)

function Armor::onTrigger(%this, %obj, %slot, %val)
{
   parent::onTrigger(%this, %obj, %slot, %val);
   if((%tool = %obj.tool[%obj.currTool]) == nameToID(jakkHammerItem) && %slot == 4 && %val)
   {
      if(getSimTime() < (%obj.client.lastJakkHammerTime + %tool.image.minShotTime))
         return;
      %obj.client.lastJakkHammerTime = getSimTime();
      %proj = nameToID(jakkHammerRangedProjectile);
      %vec = %obj.getMuzzleVector(%obj.currTool);
      %mastervel = VectorScale(%vec, %proj.muzzleVelocity);
      %a = new Projectile()
      {
         client = %obj.client;
         datablock = %proj;
         initialPosition = %obj.getMuzzlePoint(%obj.currTool);
         initialVelocity = %mastervel;
         sourceObject = %obj;
         sourceSlot = %obj.currTool;
      };
      missionCleanup.add(%a);
   }
}

I think it's a velocity problem
« Last Edit: July 19, 2016, 10:42:48 PM by Cruxeis »

%pl.getMuzzlePoint(%slot);

set slot to 0 not to the current tool
your current code will cause the projectile to be created at different muzzle points depending on what slot the item is (that wont exist)

a better way to go about your code would be to check the current image rather than the 'current item'
%pl.getMountedImage(0);
« Last Edit: July 20, 2016, 02:30:41 AM by Swollow »