Trying to make my AI hit people. So I need a formula to know the time until my projectile will hit the target and also the direction the projectile should be shot at.

Here is an example scenario.

  • The projectile shoots from the origin $(0,0)$
  • Both projectile and target will move in a straight line.
  • Speed of projectile: $v = 2000$ m/s
  • Speed of target: $u = 450$ m/s
  • Initial position of target: $x = 6000$ m, $y = 0$ m
  • Direction target moves: $b$ (above $+x$ axis). $b = 135^\circ$

Unknown variables.

  • Time projectile reaches target: $t$
  • Angle of projectile: $a$

Here are 2 equations made from the data.

  • $(v \cos a)t = x + (u \cos b)t$
  • $(v \sin a)t = y + (u \sin b)t$

How do I get the $t$ and $a$, but mostly I just need the $t$?


The easy step is to eliminate $a$ by squaring your last two equations, and summing them up. You are using $\sin^2 a+\cos^2a=1$. You obtain $$v^2t^2=[(x+ut\cos b)^2+(y+ut\sin b)^2]$$ This is a quadratic equation in $t$, which is easy to solve. Make sure you use the positive solution.


Hint: Divide both equations and you will get

$$\frac{\cos(a)}{\sin(a)}=\frac{x+u\cos(b)t}{y+u\sin(b)t}$$ and from here you can compute $t$ $$t=\frac{y\cos(a)-x\sin(a)}{u\sin(a)\cos(b)-u\cos(a)\sin(b)}$$

  • $\begingroup$ $a$ is unknown. $\endgroup$ – Andrei Oct 6 '18 at 12:58
  • $\begingroup$ I we have $t$ we can compute $a$ $\endgroup$ – Dr. Sonnhard Graubner Oct 6 '18 at 13:09
  • $\begingroup$ What I meant to say is that in your approach you still have both unknowns ($a$ and $t$) in the same equation. $\endgroup$ – Andrei Oct 6 '18 at 13:12
  • $\begingroup$ Now my solution have only $t$ in one equation. $\endgroup$ – Dr. Sonnhard Graubner Oct 6 '18 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.