0

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.

Mirac7
  • 305

1 Answers1

0

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.

user44789
  • 307
  • Thanks for this answer. However, unless I'm mistaken, an angle is required to calculate the trajectory. Testing every single trajectory is what I was trying to avoid. I need to get the angle from the point $T_1$ – Mirac7 Aug 16 '14 at 19:42
  • Oh yeah sorry for that I didn't read your question correctly. When I wrote the answer I thought you wanted to check if $T_1$ is part of a specific trajectory. But actually only a minor change is required to get $\alpha$. Use $T_0$ and $T_1$ to get the constants instead of $T_0$ and $\dot{\boldsymbol{x}}(0)$ then you can calculate $\alpha$ using $\dot{\boldsymbol{x}}(0)$ – user44789 Aug 16 '14 at 20:05
  • While the drag law you use for air resistance is physically appropriate, I'm not sure it makes sense based on the problem statement (i.e. the speed decreasing by a factor of $d$ every second). – Semiclassical Aug 16 '14 at 20:22
  • True, but I'm pretty sure that's what he wanted since he said air resistance. – user44789 Aug 16 '14 at 20:27