Andrew900460 Posted August 14, 2017 Share Posted August 14, 2017 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. Quote Link to comment Share on other sites More sharing options...
Duion Posted August 14, 2017 Share Posted August 14, 2017 Probably because projectiles usually do not exist for a very long time in the game world. In most cases less than a second. Quote Link to comment Share on other sites More sharing options...
Andrew900460 Posted August 14, 2017 Author Share Posted August 14, 2017 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. Quote Link to comment Share on other sites More sharing options...
Caleb Posted August 14, 2017 Share Posted August 14, 2017 A projectiles velocity is set when it is created by setting "initialVelocity." Assuming you're not using ballistic settings then this shouldn't change and you should be able to reference it. Quote Link to comment Share on other sites More sharing options...
Phantom139 Posted August 18, 2017 Share Posted August 18, 2017 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 methods1. 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: %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! Quote Link to comment Share on other sites More sharing options...
Duion Posted August 18, 2017 Share Posted August 18, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.