Calculate launch angle of projectile

212 Views Asked by At

I'm creating a game and am having trouble designing aiming system for AI.

How do I calculate all angles at which the projectile can be launched from point $T_0(x_0,y_0)$ with launch velocity $v_0$ to reach the point $T_1(x_1,y_1)$ given the gravity $G$ and air resistance $d$?

If $d$ is 0.1, the projectile loses 10% of its speed every second.

Note, the projectile doesn't have to stop at $T_1$, it just needs to pass through the point.

1

There are 1 best solutions below

4
On

The hard part is your air resistance.

You have a differential equation: $\ddot{\boldsymbol{x}} = \begin{pmatrix}0\\-g\end{pmatrix} - d \dot{\boldsymbol{x}}$

So for the $x_1$ coordinate we get $x_1(t) = c_1 \frac{e^{-d\cdot t}}{d} + c_2$ and for $x_2$: $x_2(t) = \tilde c_1 \frac{e^{-d\cdot t}}{d} -\frac{gt}{d} + \tilde c_2$

Now you need to bring your angle in: $\dot{\boldsymbol{x}}(0) = v_0 \begin{pmatrix}\cos \alpha\\ \sin \alpha\end{pmatrix}$

With that and $\boldsymbol{T}_0$ you get the constants. Then you simply have to check if $\boldsymbol{T}_1$ is part of the trajectory. But I think you know how to do that.

EDIT:

Sorry you have to use $T_0$ and $T_1$ to get the constants since you want to know $\alpha$. Then you can calculate $\dot{\boldsymbol{x}}(0)$ (analytically) and then alpha.