How to make a projectile curve after firing?

Hello.

I’m thinking of a sling-shot kind of weapon which fires projectiles that curves, and am looking for advice on how to go on about that with Blueprints. This image should clarify what I mean a bit.


Keep in mind that I am a beginner, not just with blueprint and UE4, but scripting in general.

Any help will be appreciated.

Will the projectile curve always be the same? (i.e same distance and velocity) Will it curve in single axis or multiple?

For single axis:
You can create a float curve in your project under content browser that defines the curve you would like to apply to your projectile over time. You can then use a get float from curve function that you pass in a variable for the time since projectile was fired to determine the delta to apply to that axis

EDIT: Function is Get Float Value where target is CurveFloat

For multiple axis:
You can create a vector curve in your project under content browser that defines the curve for all (2 or 3) axis that must have curve applied over time. You can then use a get vector from curve function that you pass in your time since projectile fired variable and get the XYZ deltas to be applied to your projectile

EDIT: Function is Get Vector Value where target is CurveVector


As an example of what Im talking about consider the following (assumes 1 game unit = 1 cm).

If you have a sling shot weapon that fires a projectile 30 meters in 10 seconds that the maximum height of the projectile is 20 meters you can create a curvefloat that has a Y axis that goes from 0 to 2000, and an X axis that goes from 0 to 3000.
Y is referencing the height of your projectile and X is referencing distance from the weapon after being fired.

For this example we will have 3 keys on your curve (defining points), 1 at (0,0) 1 at (1500, 2000) and 1 at (3000, 0). This will give you an inverted V (crude but suitable for demonstration) once you have this working you can add as many keys as defines a nice curve.

Now, if you track time from the weapon firing you know the projectile finishes its curve in 10 seconds so you can find the distanceRatio to use

distanceRatio = (timeSinceFired seconds / 10 seconds) * 3000

Now if you feed that distanceRatio into your “get float value” function identified above it will give you a Y axis value which is the height the projectile should be at based on the current distanceRatio, and your distanceRatio is your X axis value.

This pretty much defines a curve that will identify XY coordinates over time for this specific trajectory of 30m in 10s.

Obviously you would need to modify the XY coordinates based on the vector of the direction the weapon is facing.


Bonus tip:
This would work fine for that single trajectory for that single weapon but you could extend this to work for any trajectory that has this kind of firing dynamic.

If you create a curvefloat that has a Y axis from 0 to 1 and an X axis from 0 to 1 and you create an inverted U type curve, you can use this (lets call it a normalized curve) for any weapon that defines its own maxHeight of projectile at top of curve, maxDistance from weapon when projection hits ground, maxTime projectile will be in air before hitting ground.

You would calculate for a given weapon a timeRatio

timeRatio= timeSinceFired seconds / maxTime

Feed that into your “get float value” function on your curve, lets call the output floatOut (which will be between 0 and 1)

Your current Y for the projectile would be floatOut * maxHeight

Your current X for the projectile would be timeRatio * maxDistance

Again you would need to modify these coordinates based on the direction vector of your weapon


Creating the actual blueprint mechanism:

If you have a variable in your blueprint of type CurveFloat you can define it to be a CurveFloat you have created in content browser.

Drag the out pin and search for Get Float Value

The other input pin is the distanceRatio or timeRatio i describe above

The output pin is floatOut

I’m sorry, I know I’m asking too much, but could you give me an example? Like you apply a curve to the projectiles in the TP_FirstPersonBP template that comes with UE4, and then take screenshot of the BluePrint graph. This might be too much of a hassle to do for some random person on the internet, but it will help me a lot considering I’m a newbie.

Before I do that let me add an example to the answer … see if that helps

Sorry its long winded, but hopefully it points you in the right direction, no pun intended, ok it was intended

I would add that you are trying to do something that does require some knowledge of math and UE4 Curves

You should investigate how to create a Curve for this to work

Ahh, I guess this is one of the reasons why I was having so much trouble with that. I’m terrible with Math, like, Elementary School terrible. It’s why I was attracted to the Blueprint system, hoping it won’t require a lot of Math expertise…

But your explanation was not in vain, I learned a lot, I’ll try to learn more about Curve (Because I had no idea what they were in the first place). Thanks, man.

But here’s something I forgot to mention, the projectile curve changes depending on how strong you pull the pouch on the slingshot, as demonstrated by the picture I provided, the harder you pull, the more curvy the trajectory will be. So it’s kind of dynamic.

I wasnt trying to scare you :o) but there is still math involved in moving things around in a 3d environment. Curves are easy enough they are basically a plotted graph that you can use to get values based on certain input.

As for your dynamic sling shot power … the “normalized curve” (sorry its a made up name) example will work perfectly for that … you just need to adjust the 3 parameters (maxHeight, maxDistance and maxTime) based on power of the shot.

You might get away with using a lerp for that … another math based blueprint node that would allow you to create a Linear intERPolation for each parameter that basically increases those 3 values linearly based on the power of the shot … so look at LERP too.

HTH

Sorry for the late reply, I’ve been going at it these past few days but to no avail. (I’m probably stupid, though).

This is something I requested above, but can you please apply the procedure on the TP_FirstPersonBP template and take a screenshot of that? This will probably help me the most, although I realize it might be a hassle to you.

I managed to create a CurveFloat in the content browser, opened it, and got lost from thereon. I know how to define keys, but beyond that I was lost. I looked into UE4 documentation but there didn’t seem to be anything relating to this. I have no idea how to create a CurveFloat with a Y and X axis. In the CurveVector editor I can see multiple colored curves, named Y,X,Z respectively. But in the CurveFloat Editor, there is just a red line (Curve?).

A screenshot would do me wonders at this point.

Thank you, Solar, for taking the time to explain this to me, you have my utmost appreciation.

Just wanted to say thanks for the detailed explanation. Despite this post being 3 years old, I haven’t seen it explained so clearly anywhere else.

Cheers!

So for this, how exactly are you moving the actor? Set Actor Location being updated on Tick? How are you taking these floats and telling it to be at that spot? Would I multiply the actor’s forward vector that threw/shot it or ??

Because, correct me if i’m wrong but i’m left with the object’s height and distance as floats. How do i use those?

Hi

Do you want projectile moving left and right like a guided missile or just slingshot and projectile should follow gravity and fall in arc shape line?

If natural slingshot projectile, you have it in FPS example blueprint. Bullets here moving on arch, they are projectile. All what you need is to set up projectile speed and weight - in short words. Lighter and faster projectile will move in more flat trajectory, where slower and heavier will be move more on arch trajectory following gravity. This all is done in engine and you not need any math for it.

Later you can just replace example gun to slingshot model and yellow ball/bullet to rock for example.

the objects height and distance from firing weapon would need to be used to transform the vector of the projectile.

So at the point of firing you would have the direction the gun is pointing and the starting location of the projectile.

For height you should just be able to modify Z axis for location.

For distance you will need to move the projectile along the vector (direction) that the gun is pointing which would involve multiplying by the distance.

You would definitely need for the projectiles position to be updated in the tick function