Projectile trajectory horizontal travel equation

41 Views Asked by At

Working on a system for a game, I'm having a hard time figuring out a reasonable way to predict a trajectory of a projectile.

Variables:
$a$ - angle in radians
$v$ - velocity
$t$ - time
$y$ - height
$g$ - gravity

$$y=\sin(a)vt -\frac{g}{2} t^2$$

I’ve got a fairly simple way to solve for $y$ and $x$ parameters at any given time, but I’m primarily struggling with solving time for a specific $x$ and $y$.

The goal is to be able to predict when a projectile touches the ground (what time) and estimate range or distance ($x$) of how far the projectile will have traveled horizontally by then.

I get that I need to solve $t$ for $y=0$ but I’m really trying to figure out how I can plug all this into one equation I can then translate into code. Not sure if I’m thinking about this all wrong, but any help is really appreciated!

The closest I’ve come to is this:

$$t=\frac{v\sin(a) -\sqrt{v^2\sin^2(a)-2gy}}{g}$$ where $g\ne 0$.