As others have stated, projectile instances do not retain torquescript exposed variables for velocity as they typically exist for a short time period (<1000ms). A solution that you're looking for will likely use one of two scripting methods
1. Use the projectile's initial velocity, or the velocity when it leaves the weapon. This is obtained by calling %proj.initialVelocity on the projectile object (%proj) and returns a vector instance containing the velocity.
2. Calculate the velocity manually, because as you have stated, you know exactly how long it takes until the second projectile must fire. Therefore, you attach a bit to the weapon's on fire code:
Code: Select all
function myWeapon::onFire(%this, %obj, %slot) {
//Spawn the projectile (Save it as %p)
%p.pos1 = %obj.getPosition(); //You may choose to be more accurate here by using the muzzle position, circa %obj.getMuzzlePosition(%slot); Up to you though
}
Then, when the projectile instance needs to spawn the new projectile instance, you obtain the current position of the projectile and perform a simple vector subtraction:
Code: Select all
%pos2 = %proj.getPosition();
%diff = vectorSub(%pos2, %proj.pos1);
%pLife = %proj.getDatablock().lifetime;
%newVelocity = vectorScale(%diff, (%pLife / 1000));
This can then be normalized or scaled depending on your specific application. An obvious third solution would be to expose the variable on the torquescript by a simple C++ modification yourself, but that would just involve a little more work. Either way, either will work for you.
Good luck!