Game Development Community

How to Get Correct Weapon Muzzle Vector on Vehicle?

by QSquid · in Torque Game Engine Advanced · 03/20/2007 (5:43 pm) · 1 replies

Hello Everyone,

I am having a problem with the muzzle vector when I fire weapons from my vehicle. The vehicle I am working with currently has 4 mount points spread out across the vehicle, all are the same weapon but mounted in different weapon slots. When I trigger the fire action no matter which slot I fire the projectile always originates from the same location of the vehicle. I know i am triggering the correct weapons because the correct weapon goes through its fire animations. Here is the fire code for the weapon. The %slot is the correct slot but the %obj.getMuzzlePoint(%slot) is always the same.

function WeaponImage::onFire(%this, %obj, %slot)
{
   echo("SLOT:" SPC %slot SPC "MUZZLE POINT:" SPC %obj.getMuzzlePoint(%slot));
   %projectile = %this.projectile;

   // Decrement inventory ammo. The image's ammo state is update
   // automatically by the ammo inventory hooks.

   // Determin initial projectile velocity based on the 
   // gun's muzzle point and the object's current velocity
   %muzzleVector = %obj.getMuzzleVector(%slot);
   %objectVelocity = %obj.getVelocity();
   %muzzleVelocity = VectorAdd(
      VectorScale(%muzzleVector, %projectile.muzzleVelocity),
      VectorScale(%objectVelocity, %projectile.velInheritFactor));

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

If anyone has a suggestion please let me know.

Thanks in Advance.

#1
03/26/2007 (1:29 am)
Try to use muzzle correction (set the boolean inside the image datablock).