Modifying speed of ProjectileMovement component after spawn
Is it possible to modify the InitialSpeed (or otherwise make it move) after a ProjectileMovement component comes into existence in the game?
My project has a projectile (an arrow), that exists in the world before its "fired", and I want the speed at which it travels to be variable on how far back the player draws the bow. If i set the "Initial Speed" variable in the ProjectileMovement component's default settings, it flies off just fine (the component has auto-activate disabled, and I trigger it at the right time with an Activate node), so I am pretty sure everything as far as the arrow actor, as a projectile, actually works.
However! I want to modulate the speed of the arrow. So, I'm setting "initial speed" to be whatever the desired speed is (I've confirmed the value i'm feeding it is, in fact, good and correct) and then activating the component; this is where my problem is. It seems that it ignores any value set via blueprint, and going with whatever the default value is. Leaving the default at 0 just causes the arrow to unceremoniously drop to the ground, ignoring whatever value I set via blueprint.
I've also tried to create a ProjectileMovement component on demand, but it seems to behave in the exact same way. Perhaps it only cares about "Initial Speed" the moment the component comes into existence and setting it after is meaningless?
Has anyone else got the ProjectileMovement component to work with a variable speed after it already exists in the world? Or is there any other way to change the velocity of a ProjectileMovement component after it's come into existance?
asked Nov 27 '17 at 09:04 PM in Blueprint Scripting
Solved it on my own! It turns out on top of my original issue, just setting the Initial Velocity was sending the projectile on the world X axis regardless of whether or not the "Initial Velocity in Local Space" was set to true. I was tying to find a better way to launch the projectile, when I discovered the "Set Velocity in Local Space" function of the ProjectileComponent. It takes a vector input, so I just made a vector using my calculated speed for the X value, and not only did it fix the issue of where the projectile was going, it also launched it at that velocity after the component was created!
Also, for anyone else who is trying to do something similar, It doesn't appear to be able to work twice; IE if I wanted to launch the same arrow twice, it wouldn't work unless I created a new ProjectileComponent on the fly to deal with it (I also deleted the old one, but I don't think would prevent the new one from working).
answered Nov 27 '17 at 11:54 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here