I'm currently creating an AI for a robot whose aim is to shoot another robot.
All I want to do is to be able to calculate at what angle to shoot my bullet, so that it hits my enemy, with the assumption that the enemy continues moving at the same bearing and velocity.
Here are the variables that are known
- Bullet speed is: $bulletSpeed$ m/s
- $x$ and $y$ coordinates of both mine $(x_1, y_1)$ and the enemy robot $(x_2, y_2)$
- The angle between me and the enemy: $a^\circ$
- The heading of the enemy robot: $b^\circ$
- The distance between me and the enemy robot: $d$ metres
- The velocity of the robot: $v$ m/s
[Note: this may be more information than needed. Also all angles range from 0 to 360, where North is $0^\circ$ and East is $90^\circ$ and so on]
Here's a diagram to help illustrate the problem, where the arrows show what direction each robot is facing and $travel$ is the distance of the robot has travelled and $bullet$ is the distance the bullet has travelled in $t$ time:
I wish to find the angle: $\theta$ to shoot my bullet such that it hits the robot and in the minimum amount of time.
The answer should be a formula such that $\theta$ is the subject, so I can substitute the $bulletSpeed$, $a^\circ$, $b^\circ$, $x_1$, $y_1$, $x_2$ and/or $y_2$ to get an answer for $\theta$. i.e.:
$$ \theta = ... $$
What I got so far
Here's what i have got so far: $$bullet = bulletSpeed * t $$ $$travel = v * t $$
As you can see its not much.
Please help, as I really need to get this section of my AI done by the end of today and really struggling.
Please also explain your solution so I can understand it. Many Thanks