Game Development Community

Tha actual attack function

by JesseL · in Torque Game Engine Advanced · 10/02/2008 (2:43 pm) · 3 replies

I have been looking at script after script, I see all the functions that can make Kork do all kinds of crazy things however in all of them, I can not seem to find the single function that actually makes him "Fire". Where the projectile is created and set on it course.

Most of what makes sense could somone please point out the function that actually does the "shooting"?

About the author

I just realized that if I wanted to create a cat that caught on fire and ran up a telephone pole and then burst into a blue waterfall. That wouldn't be to hard!


#1
10/02/2008 (3:04 pm)
I think the projectile is not created in script, rather in code in T3D/shapeImage.cpp, you might want to check that.
#2
10/02/2008 (3:30 pm)
Nope, it's done in script, in crossbow.cs:
function CrossbowImage::onFire(%this, %obj, %slot)
{
   %projectile = %this.projectile;

   // Decrement inventory ammo. The image's ammo state is update
   // automatically by the ammo inventory hooks.
   %obj.decInventory(%this.ammo,1);

   // Determine 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;
}

The function that is initiated when the trigger of a weapon is pulled can be changed via script as well. Take a look in the definition for CrossbowImage:
datablock ShapeBaseImageData(CrossbowImage)
{
        ...
// Fire the weapon. Calls the fire script which does 
   // the actual work.
   stateName[3]                     = "Fire";
   stateTransitionOnTimeout[3]      = "Reload";
   stateTimeoutValue[3]             = 0.2;
   stateFire[3]                     = true;
   stateRecoil[3]                   = LightRecoil;
   stateAllowImageChange[3]         = false;
   stateSequence[3]                 = "Fire";
   [b]stateScript[3]                   = "onFire";[/b]
   stateSound[3]                    = CrossbowFireSound;
         ...
}
The script line highlighted above is the name of the script function that the engine is to call when the weapon enters the "fire" state.
#3
10/03/2008 (1:23 am)
Oh, that solution is really cool. I just gave it a thought what could be done with multiple states. Thanks Mark!