Flying Enemy AI Flight patterns

I want to create enemy planes/ships that fly towards and around a target of choice and attack, the veer off or fly past then return to continue attacking until target is dead or the enemy plane is dead. Here is an example of the flight I am looking for in the animation at the top of the page.

How can/should this be achieved?

I don’t know how it should be done, but here’s the outline of how we did it. I didn’t look at your video because you are asking for how to Dogfight.

AI has an array of potential live targets and their location.
AI has an valid attack range value matching the weaponry it possesses. For example, lifetime of projectiles determines how far away the attack should start.
AI has a break off range value saying at what distance to target is will begin evasive action. Otherwise you will collide with target.
AI has either a randomized distance or time that it should travel before resuming attack.

  1. AI Selects target actor getting location to fly to (adjusted by velocity of target taking into account AI’s own velocity)
  2. AI Selects evasion target to fly to when it reaches break off range. This will be some realistic random angle beyond the target (e.g., above 30 degrees and beyond target by evasion distance, should both be randomized).
  3. When length of vectors between target and AI reaches Attack Distance, begin firing. Be sure you have leading code in place dependent on the direction target is going. The more speed target has and depending on the angle AI has to target forward vector, the more leading required. Target’s forward vector and velocity are friends in this. Be careful to randomize the projectiles path or you create an aimbot.
  4. When length of vectors between target and AI reaches break off distance, alter angular velocity to fly toward selected evasion point rather than the target.
  5. When evasion point is reached, select target again as the point to fly to and begin the process again. The direction to fly at reaching this point will probably be determined by the forward vector of the target (or they will get away).

Some things to consider, including:

  1. Possibly changing targets at this point if logical, for example, first target out of range and another is within range
  2. Flying in a randomized direction to another point where the next attack should begin, we do this to make the AI behavior look a little less mechanical.
  3. Shifting to new evasion or retreat paths if the target begins attacking back. This usually is unnecessary because with both vehicles moving, the basic logic makes them look okay.
  4. Different modes of attack, you have effectively described Dogfighting, but as an example, Broadside attacks are possible with different types of flight pawns. This change involves seeking to parallel the course of the target rather than flying at it.
  5. Since our flight pawn is space oriented, paths have to be checked to ensure there is nothing in the way (asteriods, space stations, friendlies etc). For a WWII sim, the ground, friendlies, and mountains are the only thing probably to consider. Line traces to these points are required at the moment they move to their target or evasion points.
  6. Pick more than one evasion points to fly to after break off. Meaning, have a final evasion point to reach but an array of points to get to that final point. This allows nice looking curves in flight that make it look like it’s being impacted by thought.

Sorry I can’t provide code for this, it would take me hours to pull out and explain the thousand lines of C++ we use in our AI attack control. Plus there is a mess of BP doing the physics to move to a specific point. We determine the path to take and firing times in C++ then pass a vector to BP to actually get there. The first step is to just get a BP going that will fly the AI from point A->B, then A->B->C. Then work on having the points defined by AI control logic (including firing and leading).

1 Like

Actually its a stationary target for the enemy ai, the video is technically a stationary target, even though its a tailgunner. Its the attacking enemy planes that I liked.

Anyway, your path sounds similar to how I was approaching, but not that far along. I am going to reread your post and make some notes to compare. Thanks!

Are you using physics or rotation velocity?

That will make it a lot easier having a stationary target.

Sorry, I just realized I didn’t answer your question. “Set Physics Linear Velocity” and “Set Physics Angular Velocity” within the BP that handles our flight pawn locomotion. These “chase” a scene component we place far out in front of the flight pawn whose location gets set according to the vector provided by the C++ AI Logic that determines where the flight pawn should be heading. I didn’t do the locomotion portion, our modeler did in BP. I just provide the intelligence for the heading of the current (i.e., current frame’s) waypoint.

1 Like