Download

Artillery Turret Tangent Arc

Hello,

How can I create my turret to aim at a proper elevation so the projectile fired will aim correctly upward, and the round lands on the target in a distance? I’m imagining a blueprint like this already exist, but not sure what it is called. Imagine an Artillery shell firing. How does it know how high to aim the barrel at the selected target, so the round drops onto the target?

Trying to avoid breaking out my Trigonometry book or going back to quadratic formulas.

You will most likely want to have a look at this Wikipedia article.

Just keep in mind that it won’t guarantee a 100% hit, depending on the size of the target and simulation error accumulation, but the results should be really close.

This looks like it could be a solution, but I’m curious how I could apply this type of formula into a blueprint. Clearly the formula is structured differently. I’m surprised there isn’t a function already created to solve this inside of Unreal. Or perhaps I’m over looking the function somewhere?

I could be wrong, but I’m pretty sure this formula isn’t included as a function in the engine. It is indeed a popular thing though, that gets asked every now and then.

As for the structure of the formula, it is given with only x and y for horizontal and vertical distance. This simply means you have to project your 3D distance vector between the initial and target position, into the vertical plane that passes through both of them.
In other words, you first have to find the yaw toward the target, and then use the (target - initial position) vector and project it to get the formula’s x and y.
You could also directly project the 3D vector into the vertical plane, but you would lose the yaw information in order to rotate the cannon.

I have my Yaw information on a different platform. Imagine a tank where the Yaw is the Turret itself, and the Barrel is the Y. This should make things easier because the Turret itself is using a “Find Look at Rotation” to align itself and the barrel to the target. Now the hard part is applying the functions in question to make the barrel arc correctly to the target.

In this case, do I somehow apply this formula you linked utilizing the x and y only still? Perhaps a “Get Distance To” blueprint function will help solve the problem?

Your setup makes things easier to explain, since the Find Lookat Rotation should give you the plane you want to work in.
The y in the formula is the difference in altitude, z, between the turret and the target (which may need to be adjusted to account for the elevation of the cannon). The x is the horizontal distance.

The only situation I would see this be an issue, is if your turret is on uneven or slanted terrain, as the orientation of the cannon may cause a left/right inaccuracy. On flat ground, the results should be pretty good.

KashiKyrios,

It’s funny you mentioned uneven terrain, because uneven terrain is exactly the environment the cannons will be sitting on.

I’m also having trouble utilizing the formula to translate into Blueprints. Basically nothing I have tried is working. I am assuming “g” represents gravity in the formula, but I do not have the integer for Gravity.

My projectile is a blueprint with the “ProjectileMovement” component attached. It does have a “Projectile Gravity Scale” but this value is 1.0. I am assuming the real gravity code is deep inside this component. Perhaps I can utilize the “ProjectileMovement” component to behave like an artillery round?

Just saw the notation. Going to try again:

In the equations on this page, the following variables will be used:

g: the gravitational acceleration—usually taken to be 9.81 m/s2 near the Earth’s surface
θ: the angle at which the projectile is launched
v: the speed at which the projectile is launched
y0: the initial height of the projectile
d: the total horizontal distance traveled by the projectile

What should I put for the “Arctan”? Just TANd (Tan Degrees) ?

Ok, I’ve created a layout of my function in the blueprint. This is as simple of a breakdown as I can get. It is KIND OF working, but my shots are very short. My gravity variable is 9.81 and my Projectile Velocity is 20,000. Also, my turret and barrel’s world location is 0,0,0.

My results on my barrel comes to 8.22+. Based off my screenshot, what am I doing wrong? Please use the link so you can zoom in on the blueprint. This function is based off the wikilink above.
http://img.photobucket.com/albums/v72/Teriander/Barrel_Projectile1.jpg

http://img.photobucket.com/albums/v72/Teriander/Barrel_Projectile1.jpg

If you can’t view the image, here is a download version:

The arctan is usually “atan” in programming languages, and this holds for Blueprints as well. Atand will give you a result in degrees, so you can go for this one.
I’m honestly not sure how you can get the gravity; it seems there is a node to get the world gravity, but it requires a world settings reference, and it appears to be different from the gravity set in project settings.
For the time being, you can just use 981 (or whatever value you have). Also, be careful with units: the calculation is done in meters, but UE4 works in centimeters. I don’t think it has an effect here, but better check anyway.

As for the ProjectileMovement, I’m not familiar with it, so I’m afraid I can’t offer much help with that.

EDIT since I didn’t see your latest post: The formula considers the initial position to be at coordinates (0,0), so you will want to use the difference between the target’s location and the barrel’s.
Once you have this distance vector, project it along the up vector to get the formula’s y, and along the normalized horizontal distance to get the formula’s x.
There’s also a mistake in how you grouped the terms in the formula: v^4 - g(gx^2 + 2yv^2) should be grouped as v^4 and g(etc.), so basically multiply by g before subtracting from v^4.

Another edit: I just saw your barrel was at coordinates (0,0,0), so that will work (but the more general case of getting the difference is preferred).
Here’s a screenshot of how I got the formula’s x and y coordinates:

&stc=1&d=1473663254

Thanks for this Kash! I will try this today and see how it works out!

Well, it turns out I was wrong in my 2nd post: there IS a function for this in the engine: Suggest Projectile Velocity.
It outputs a velocity vector based on the initial velocity, the initial location and target location.

I’m not sure exactly how the Projectile Movement Component works, but it should help you anyway. You can probably use the output velocity vector to help pitch the barrel to the proper angle.

Hmm, this sounds like an viable approach. I’m going to have to research how to pull this information and apply it to my barrel. Currently my Projectile is a separate actor that has the “Movement Component” applied to it. Works great. But currently the projectile’s projected path for landing is unpredictable. Surely there is some way to know where its going to land and to land at a specific target. While passing that information to the barrel.

Are you suggesting I create a editable variable linked to the Projectile Velocity and vector on my Projectile Actor, and pull this information into my Barrel’s actor?

Yeah, it looks like everything I’ve tried or trying doesn’t seem to work. Not sure what I’m messing up.

If anyone is interested in assisting for a compensation please let me know and how much. I’m willing to pay to have this resolved as I am constantly running into roadblocks.