I'm developing a submarine game and found a mathematical problem that exceeds my knowledge.
A submarine has $x$ and $y$ coordinates in the plane, a speed $v$, and two angles: one indicates the direction in which it moves and the other direction it shoots. If a submarine in motion plans to shoot another that also is in movement, which the angle of rotation of the weapon that results in the destruction of the target?
Besides the known data of the submarines we know that:
- Rotational speed of the weapon: $\tfrac {20^\circ}{\text{tick}}$.
- Shooting speed: $20 - \frac{1200}{\text{distance from target}} \frac{\text{space unit}} {\text {tick}}$.
- Maximum shooting speed: 3.
The submarine is a rectangle of width $w$ and height $h$.
Does anyone have any idea how to get a formula? The case that I will need more is when the shooter is stopped so, if someone can at least for this case, I'm grateful.
Let's assume that the shooter is not moving, that the target is moving on a known trajectory at a fixed speed. Calculate where the weapon's trajectory and the target's trajectory cross. Then calculate when each of them arrive. If the weapon arrives $k$ ticks sooner, then recalculate based on waiting $1$ tick, $2$ ticks, etc. (not necessarily $k$ ticks since the shooting speed depends in distance to target). If instead the target arrives before the weapon, then turn the weapon 20 degrees (leading the target) and recalculate as previously.
If instead the shooter is moving at a fixed speed, then add that speed to the target and pretend the shooter isn't moving. This is equivalent to changing the reference frame to be centered at the shooter.
All of this depends on the physics of the game. It seems strange that shooting speed depends on how far the target is. It also seems strange that the weapon doesn't slow down in the water, and that gravity doesn't act on the weapon.