AIR COMBAT

We would like to create NPC airplanes that have the ability to engage in air combat.

The Objective

Since these airplanes do not have missiles, they can win only if they can bring their guns to bear on you at close range.

To do this, the NPC airplane must be able to handle 3 different situations:

  • Where the NPC has the advantage, e.g. the NPC is on your tail
  • Where you have the advantage and the NPC must escape
  • Where neither has the advantage
  • For now, we will assume that both airplanes have identical performance and starting speed.

    Where the NPC is on Your Tail

    If the NPC is on your tail, they will want to stay there. This means the NPC will want to follow your flight path. However, they cannot simply copy your maneuvers immediately (at Z2 below), but must wait until reaching the place where you began your maneuver (at ZC below).

    There are several ways to do this. In real life, a pilot will try to estimate what the off-angle will be at that point and turn in. In our simulation, we can simply determine when the NPC is abeam of the center of rotation (at ZC). At that point, the NPC can use an isosceles triangle to compute the turn rate required to eventually reach the current position and heading of the target.

    If we knew that the turn rate for the target has not changed, the NPC could simply use that turn rate. However, that is extremely unlikely. Thus, we will compute a turn rate for the NPC based on the current positions and headings of both airplanes.

    In the above illustration, the target is located at C and the NPC is located at B. The off-angle is AngleA. The triangles ACD and ABD are mirror images of each other. We can solve for the right triangle ABD.
    * AngleA on triangle ABD is 1/2 of the off-angle.
    * AngleD is 90 degrees.
    Since a right triangle has 180 degrees:
    * AngleB = 180 - AngleA - AngleD (90), or 90 degrees - AngleA.
    Since BD is located midway between C and B:
    * SideBD = SqrRt((Cx-Bx)^2 + (Cy-By)^2)/2
    Now we can compute the radius:
    * Radius = SideBD/COS(AngleA)
    And the Turn Rate:
    * TurnRate = (180/PI())*Speed/Radius

    Here is a simple program which you can use to visualize the results. In this case you are controlling the blue airplane and the NPC airplane is reacting to your moves.