Dynamically Change the Velocity of a Projectile Movement Component

Hello!

I’ve spent many hours the past several days trying to figure out how to have a laser/energy blast shoot from a moving vehicle at a proper velocity.

Here is the setup:

Hero Ship, Blueprint Class of Pawn. Has the Arrow as part of the hierarchy so that the laser blast can spawn at the correct coordinates. Max speed of the ship is Mach 2 displayed in the HUD as KPH, in this case, 2414 KPH. My understanding, and please correct me if I’m wrong, is that movement in UE 5.1 is centimeters per second. So the max speed of the ship is 67056 CM/S.

The projectile is also a Blueprint Class of Pawn and has a Projectile Movement Component as part of it’s hierarchy. It’s initial speed is 15000 CM/S.

Everything is fine, as you might imagine, to a point; I pull the trigger on the controller, the laser bolt spawns from the correct coordinates and follows the correct vector.

The problem, as you’ve probably already guessed, comes about when the ship’s velocity nears that of the laser bolt. In this case, once I’m at about 460 KPH, the laser bolt is significantly slow, and at 540 KPH, it’s starting to come out backwards.

What I have been unable to figure out, is how to dynamically increase the velocity of the laser bolt’s Projectile Movement Component so that as the ship’s velocity increases, the velocity of the Projectile Movement Component has also been increased.

Increasing the Projectile Movement Component’s Initial Speed before it’s spawned hasn’t worked, and changing it’s velocity after it’s spawned hasn’t worked either.

I’ve seen quite a few questions that are similar, but any solutions that have been provided I cannot get to work.

If anyone can point me in the right direction, I sure would appreciate it.

“Increasing the Projectile Movement Component’s Initial Speed before it’s spawned hasn’t worked, and changing it’s velocity after it’s spawned hasn’t worked either.”

This statement was not exactly true. I had started by giving the Projectile Movement Component an Initial Speed of 15000. I kept increasing this default value manually with no results other the a Projectile Movement Component moving so fats that it wasn’t visible, yet for some reason, once the vehicle started reaching maximum speed, the Projectile Movement Component would appear to come out backwards.

The biggest issue was me and my thought process; I was thinking in terms of Velocity. The solution was quite simple when I switched that to Thrust. I created a float for the initial speed of the Projectile Movement Component, set it’s value to 15000, set it to Expose on Spawn, and in the construction script for the Projectile Movement Component, plugged it into the Initial Speed.

In the vehicle blueprint, I just took my Thrust variable, connected it to Add (set to 15000) and plugged that into the now exposed variable in the Spawn Actor from Class:

Now when I fire, no matter what the Thrust of my craft is, the bolts are flying out correctly.

1 Like

You can do the same with velocity. Also, consider keeping the projectile speed inside the projectile and only pipe in player’s current speed / velocity, as in:

This way you do not need to hardcode projectile velocity outside the actors who care about it the most. It may be irrelevant if it’s a single value but if you have a blaster that can take different type of ammo, each having different speeds, it’s more natural this way.