I know that the Projectile object doesn't appear to have any functions for returning velocity, and the ShapeBase object does have a getVelocity function, but the Projectile object doesn't inherit from that.

well my reason for needing this, is because i have a projectile that being fired from another moving projectile (don't ask me this is someone elses code I'm modifying), and I want the second projectile to inherit the velocity of the object it's being fired from. I know there is a variable in the ProjectileData class but it doesn't seem to have any effect on it.

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:

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:

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!

Robert C. Fritzen (Phantom139)Founder of Phantom Games DevelopmentTorque Enthusiast Since 2009

I would probably just delete the projectile and create two new ones. Have the projectile "explode" when it should fire its second projectile and in the explosion create two new projectiles, one with the same velocity and vector as the first one.Or you can just use the initial velocity since it will stay the same and use some other method.The problems only really arise if you use ballistic projectiles, since ballistic projectiles change direction and speed in their flight.But in case you want a slow ballistic projectile, I would probably use a whole other class for that, for example an item or player or vehicle, they can also fly and often have more callbacks.