How can I determine trajectory from distance and time, without initial velocity?

I'm attempting to develop a Mortar that needs to lead it's shot to the target enemy. The shot will have a pre-determined constant flight time of (2.5 seconds) and it will have where the enemy should be after that time (if the enemies motion is constant).

I'm struggling to figure out the proper equation to get initial velocity (and fire angle required) from just the distance from the predicted location, and the amount of time taken (2.5 seconds).

• Welcome to the site. Remember to search first and post second. I'm going to vote to close your question as a duplicate in a moment. If it does end up being closed, and you think it's different, or you have some specific problem, feel free to edit your question to reflect that. Dec 19, 2013 at 15:35
• possible duplicate of How can I find a projectile's launch angle? Dec 19, 2013 at 15:35
• – House
Dec 19, 2013 at 16:15
• – House
Dec 19, 2013 at 16:17

Sorry if this answer is a bit too general, but to be more specific I would have to know whether this takes place in 2 or 3 dimensions, whether the world is flat, etc.

For any projectile motion calculation, it is easiest if we analyse each axis (dimension/component) separately. The two equations used here are:

d = u * t (for no acceleration)

d = u * t + 1/2 * a * t^2 (for the vertical component, where gravity is acting)

I will also use 'u' to represent the initial velocity, 'a' to represent acceleration and 'g' to represent acceleration due to gravity (approximately 9.8 meters per second squared).

Hopefully you have some basic understanding of vectors and kinematics, if not, let me know and I'll fill you in on what you need to know.

From here forth, I will assume that you have two horizontal axes and one vertical axis.

Given that there is no acceleration occurring in the horizontal axes (other than friction, but in the context of a game, it becomes computationally very expensive to calculate this), the initial velocities along each axis are given by:

u = d/t

where d is the distance traveled along that axis and t is the time taken to travel this distance.

In the vertical axis, the initial velocity is given by:

u = d/t + gt/2

where d is the vertical offset of the final position from the initial position.

Since you specifically asked to find the angle at which the projectile should be shot, the workings are provided below:

horizontal component distance = sqrt(ux^2 + uy^2)

where ux and uy are the initial velocities in each axis (assuming z is vertical).

angle from horizontal = arctan( uz / (sqrt(ux^2 + uy^2)) )

If your terrain is flat, then uz = gt/2, and you can ignore vertical displacement.

If your game is side-scrolling, then there will be only one horizontal axis.

If your game takes place on another planet, uses non-realistic velocities or the shell seems to travel strangely, try using a value other than 9.8 for g.

EDIT: Added code formatting for legibility

• Thank you very much! you are amazing! i understand everything now and feel like an idiot that i couldn't figure out the vertical component Dec 20, 2013 at 2:20
• @AussieTerra You're welcome. Good luck with your game! Dec 20, 2013 at 2:36

A quick google search gives you all the equations you'll need. Obviously you'll still need to account for external forces, but this should get you started.

As for the angle, break the velocity into its components of x and y. These should create a nice right angle you can apply trig functions to.

• thanks for the reply, though how do i get the initial velocity? i assume working out each component, which for the horizontal component is the distance between target and mortar over the duration (2.5 seconds), though how will i get the vertical with just the distance time or the newly found horizontal component? all i really need to figure out is how to get the initial velocity given d and t Dec 20, 2013 at 1:04

(this is a clarification of the equation in peter's answer)

There is a very simple way to calculate the initial velocity.

using the equation D = V * t + (1/2) * a * t ^ 2 as mentioned in Peter's answer is all you need.

• V - initial velocity vector of projectile. This is our unknown variable.

• D - vector representing the displacement between your point and the target point

• a - vector acceleration: Earth gravity will be (0,0,-9.8) in terms of meters per second squared, or the equivalent in your choice of units are.

• t - 2.5 seconds

(assuming a Z coordinate facing up)

If on level ground, D.z = 0, then V.z would simply be a.z / 2 / t. You could also use other values of D.z to simulate firing at an uphill/downhill target.

The x and y coordinates V would simply be chosen so that the V.x * t = D.x and V.y * t = D.y, since horizontal acceleration is zero.

If you want angle above horizon, that's just atan(V.z / sqrt(V.x^2 + V.y^2));

• Thank you very much for replying! both you and Mmarss helped me out a lot, i'm extremely grateful Dec 20, 2013 at 2:52