# finding the angle to launch a projectile at a 3d coordinates

I have a game where the user can shoot a bullet and the bullet flies through 3 dimensional space and eventually hits the ground somewhere. My question is how can I calculate the pitch of the angle to make the bullet hit a specific coordinates with possibly different elevations.

My known factors are:

• The gravity force
• The initial projectile velocity
• The shooting position
• The target position

In my case I do not need to factor for target movement, I am trying to make something similar to an artillery weapon that fires into the sky and have the bullet land somewhere else at a target. Because I am trying to make an 'artillery-like' weapon I need the weapon to aim up at the sky, not directly at the target.

• You mean parabolic projectile motion? en.wikipedia.org/wiki/Projectile_motion – Mars Aug 18 '16 at 11:04
• Yes, except in 3 dimensions, as far as I can tell that wiki page only accounts for 2 dimensions? And I would need to find the angle to fire the projectile at. – ZeroByter Aug 18 '16 at 11:17
• Well, the movement itself is planar. You could rotate it to be happening on XY plane, do all calculations, and rotate it back. That's the first method. Not so clean. Second would be baking this rotation directly into formula. Try to find it. Hope I'm not directing you into dead end, but for me it seems good. Couple of calculations on paper won't harm though ;) – Mars Aug 18 '16 at 12:09

Ok, I don't have Images to help you, but heres how I would try to tackle the problem.

Your ultimately trying to calculate a parabola. We should start by calculating the distance between the firing point and landing point. I don't know how to adjust for the height differential.

Now, lets talk about the projectile. If we were to track it in the game, technically, along it path, if it were a line going from -x to positive x, and lifting on the y in its arc, we really don't sway left or right on the z axis. so Really, the math problem will boil down to a 2D problem.

So, in 2d, a parabola is basically y2 = x. If y=0, your at the peak, and x =0. But As you go down on the y axis("that's what she said"), technically, both x and -x are possible solutions, a positive one and a negative one.(Again what she said)

To visualize a little more, your position will be one of those two answers, and your target is the other. There are other methods of "changing" the parabola to fit your height scenario, but I want you to try to remember the y2=x part. Its what your doing in a nutshell.

That parabola is the key. Technically, you just need to take a sample of two points on one arc, and translate that into whatever method you use for rotation, like vector or matrix or however other ways you can define an angle. Really, you can make the barrel point at the target, then you add the rotation in degrees.

I would also like to point out though, that modern artillery takes in to account how much force to use when firing the projectile. Technically, you can a variety of angles with different charge to reach many angles. This control may have cool outcomes for a game. Like programming one artillery piece to fire several rounds in succession, that ALL STRIKE SIMULTANIOUSLY! Or could simplify your targeting system. Instead, you give it a angle that is "close" and then calculate how much force to give the projectile. This fact could make your approach this a bit different. For example, you may always want to have a nice curve, instead of some straight up arc that seems to go forever before making a quick U-ey and come screaming back down.

So we can start by turnin your Artillery piece to face the target, then measure how far away, and the difference between heights. If we want to pick the arc, lets say the same one I used as an example(y2=x), we need to find out where we fit on that scale. The mid-point between the two points is where y=0, so lets cut that number in half, and use that as our "y" input in that formula. X could end up being either one, but it doesn't really matter, YOU have your arc and where your stand on it. Now sample the arc from your point towards the center by the length of your barrel, turn those two points into a vector, and theres your rotation. Now you'd have to do some more math to figure out what velocity to use, but really, you only need to calculate how to "hit" the "peak." I'd imagine you have some constant force of gravity, so it will "slow" as it rises at the same rate it will "speed up" as it falls. So that velocity requirement will grow paraboliclly as distance increases, so that distance you measured between each point will be important, so there probably is means of using the same arc formula to figure that out.

All this might also be helpful to consider if you want these items to act autonoumsly, getting optimal rounds per minute on a target under AI control.