Author Topic: Help with a shotgun projectile  (Read 609 times)

Hello, I was wondering if anyone could help me be able to spawn the projectile that shoots from Gravity Cat's firearm's. I've been having a lot of trouble with this and it's quite problematic for me. Thank you

this is how the as50 spawns projectiles
Code: [Select]
function gc_as50Image::onFire(%this,%obj,%slot)
{
  gc_as50ZombiesAmmo(%this,%obj,%slot);
  %obj.gc_as50Ammo -= 1;
  if(%obj.gc_as50Ammo < 1) %obj.setImageAmmo(%slot,0);
  %vector = %obj.getMuzzleVector(%slot);
  %objectVelocity = %obj.getVelocity();
  %vector1 = VectorScale(%vector,%projectile.muzzleVelocity);
  %vector2 = VectorScale(%objectVelocity,%projectile.velInheritFactor);
  %x = %y = %z = 0;
  %mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
  %p = new(%this.projectileType)()
  {
    dataBlock = gc_weaponRecoilHeavy;
    initialVelocity = VectorAdd(%vector1,%vector2);
    initialPosition = %obj.getEyePoint();
    sourceObject = %obj;
    sourceSlot = %slot;
    client = %obj.client;
  };
  %projectile = %this.projectile;
  %spread = 0.00002;
  %shellcount = 1;
  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() - 0.5) * 10 * 3.1415926 * %spread;
    %y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
    %z = (getRandom() - 0.5) * 10 * 3.1415926 * %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;
}
you can mostly just do
Code: [Select]
%p = new (Projectile)()
{
dataBlock = gc_as50Projectile;
initialVelocity = "0 0 0";
initialPosition = "0 0 0";
sourceObject = findClientByName("Halt");
sourceSlot = 1;
client = findClientByName("Halt");
};
MissionCleanup.add(%p);
not sure if source object is needed, it should be the gun, but instead I made it a client (you)

(that should spawn a stationary sniper bullet at position 0, 0, 0)

Thank you for this, it helped a lot!