Fighter control system

Started by
9 comments, last by conq 10 years, 5 months ago

Hi everyone,

I want to create a system which controls fighters in combat (i.e. aerial combat). How would I go about that? Would I use some kind of flocking system?

Thanks.

Advertisement
Probably not. I thought about this type of game many years ago, and my plan was to make the decisions be about maneuvers that the pilot can perform. You can find a list here. You can then try to have some probabilistic model of what the other planes will do and try to compute a utility (i.e., a score) for the resulting positions after each hypothetical maneuver you may take. The action with the highest expected utility should be chosen.

You can also have something a bit dumber that will have a list of condition-maneuver pairs that you can check sequentially. When one of the conditions is satisfied, pick the associated maneuver.

Anyway, I never implemented any of it, so I am not sure how good you can make it look. But if you are completely lost, it's probably a reasonable place to start.

the most superior ai is simply detecting success and failure. just different ways to do it.

I don't think flocking is likely to be a commonly useful fighter behaviour. The closest realistic situations are approaching objectives in formation before combat, which is more constrained than random flocking (there is a designated leader and fixed positions), and pursuit of enemies, which is going to be far more complex than trying to go where the enemy is (with coordinated team positioning, choices between aligning weapons to shoot and steering to reduce distance, evasive maneuvers, accounting for multiple weapon ranges, etc.) and carefully combined with other general behaviours.

Omae Wa Mou Shindeiru

I actually have experience writing space combat AI, so I'll try and brain-dump the interesting pieces that I can still remember clearly.

Steering
Having some form of steering-forces system is actually very useful. It takes a little creativity to rig up constraints to the steering, though, so that your fighters can't turn on a dime or go backwards. Traditional flocking forces are not used much, but you can still get good mileage out of forces that help align your fighters and draw them towards fixed points in a formation. As far as formation flying and avoidance go, steering is probably the simplest way to get the job done.

Pre-packaged maneuvers
This is a bit tricky to integrate with steering unless you just turn steering off while a maneuver plays. The easiest way to do these is to draw 3D splines in an art or animation program, export them, and have the spline oriented to the fighter's current position (and scaled by his current velocity - never forget that!) then just interpolating the fighter along the spline. This is powerful and allows for any type of interesting maneuver for solo pilots.

You will probably get very limited use out of this because it shows off nicely and looks fancy, but in a real dogfight, it's more or less meaningless to play a canned animation. You'll get better mileage out of dynamic maneuvering logic.

Coordinated Flight
There are three types of coordination you need to implement: avoidance (never crash into things), formations (handled by steering, as above), and what I just called "interplay." Interplay is basically just what fighters do with enemies nearby. This is where the bulk of your interesting logic will live, because it's how you get the really meaty "AI" bits to function. Interplay covers the actual dogfight logic - both between enemies and cooperating allies. It's important, if you want a good looking fight (versus a realistic one), to have your AI cooperate between enemies and allies uniformly. I'll get to that in more detail in a moment.

Avoidance is easy: never create a maneuver that draws you too close to the ground or flight ceiling, and never steer into another plane. Avoidance forces in the steering system can accomplish this but you'll have to be careful with the tuning.

Formations are covered by steering forces already, just build a force that attracts a plane to his appointed slot in the formation. Pre-designed formation plans are fine.

Interplay
Probably 90% of your time tuning and refining the AI will be sunk into this area. The actual nature of your fight depends almost entirely on the types and quantities of weapons available to your craft. I worked with a standard lasers-and-missiles AI, so my experience is probably pretty different from a more "realistic" modern-day setting with long-range missiles, radar, and other factors.

I can probably dig into this in more depth if you can provide some details about how your game is designed and what weaponry you plan on including.

However, there are some general guidelines:

- If you want a realistic fight, it's not going to look good, but it may be appealing to hard-core sim fans.

- If you want a visually appealing fight, you need to control a few things. First and foremost is "time to kill." If your TTK is too short, you'll kill things before the player gets to see. If it's too long, the player gets bored. Secondly, you need to control relative positions of craft. If they tend to stay in visual range and in the easily-visible view cone of the player, it's easier to make them look cool. Finally, you need good dynamic maneuvering code, which I'll cover last.

- Use combat chatter dialogue to cover up visual obstruction; i.e. if the player can't see a cool shot, have his wingman call it out with some appropriate dialogue to make the player aware that something happened. If your game design permits, have enemies play taunts and things as they maneuver around to help reinforce the idea that they're "opposing" and messing with the player a little bit.

- Remember that the best AI in the world is probably boring to fight. Tune for entertainment value unless you're trying to make a military training sim. A fun fight generally involves a couple near misses, the player barely coming out on top, or at least with his heart pounding a bit. If your testing of the game doesn't crank up your adrenaline, you've done something wrong.


Dynamic Maneuver Generation
This is the real magic of flight-based games. Players want to see cool stuff - not just from their allies, but their enemies as well. They want to have to follow a fighter through a gut-wrenching high-G turn to make a shot; they want to see their buddies corkscrew and barrel roll to evade missiles; and so on.

The trick in my experience to good dynamic maneuvers is to have archetypes available. If you're making a realistic type sim, or just a modern air combat game, buy a couple books on aerial combat tactics and learn the common behaviors of pilots in real situations. You can get a ton of inspiration from this. There's a few good books out there that cover relatively up-to-date aerial tactics that you can probably find easily online. Unfortunately mine are all in boxes in storage or I'd suggest a few titles.

The way you do this in code is to set up a general archetype along with a purpose for using it. Certain evasive maneuvers are good for breaking radar locks; others are good for dodging missiles; yet more are good for tight furball engagements where you're in close and using shorter-range weaponry. Likewise, there are maneuvers for things like getting into position behind an enemy, drawing an enemy into a trap set by a wingman, breaking up enemy formations, and so on. Build up a playbook of these maneuvers and how they should be used in combat.

Once you have that list, add a scoring system. Utility is a tempting basis for this but can be very, very hard to tune. I'd recommend a simple "personality" system where some pilots prefer certain maneuvers. When you spawn a pilot - friend or foe - give him a randomly selected subset of your playbook to choose from, and have him draw appropriate maneuvers from that subset.

Finally, once your pilots know how to choose a dynamic maneuver, it's time to animate it. Some people may be surprised by this, but I found the easiest way to do this is with a keyframe system coupled with a steering forces system.

Here's how it works: you create a simple steering force which can push the plane in any arbitrary direction. The actual force - direction and magnitude - is controlled by interpolating between keyframes. Each keyframe defines a critical "moment" in the maneuver. So a simple loop-the-loop might start with a steady upward force that pushes the nose of the plane vertical until he flips over completely, followed by a graceful degradation down to zero force to stabilize once the loop is done. A barrel roll is similar but just a force that rotates the plane along its axis of attack, and so on.

Once again, remember to scale the keyframes by the expected velocity of the plane, or he'll make really abrupt speed changes that look terrible.



I think that's all I've got... feel free to ask any questions you've got if that's unclear :-)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This in its full extent is a problem of handling uncertainty, and planning and taking actions which result in optimizing future utility of the situation. You want to be put into the best position for a firing solution while at the same time avoiding being vulnurable. SInce you dont know what the enemy object will do you have to move to positions offering the best future possibilities.

It of course is even greater complexity if cooperation of multiple objects is desired.

--------------------------------------------[size="1"]Ratings are Opinion, not Fact

This will possibly repeat some of the feedback already given but a lot of this will depend on what type of game you are creating. If you are aiming at a flight simulator (or something close) then there a variety of maneuvers (such as the Immelmann turn) that could be implemented (and which flight simmers would probably hope to see). If on the other hand you are developing a real time strategy game then you can probably get away with simpler movement AI that gives the impression of real flight without overloading the processor with AI management (critical as the number of units for the AI to control in a RTS game is likely to be higher than in a flight sim).

Personally (for a RTS) I started with simple flocking / collision avoidance code (which quickly gave me something good to look at and work from) before then adding unit targeting (flight to a waypoint or target another aircraft). From there I added formation flying (flight towards a constantly updated waypoint which is actually a position in a formation).

What really helped was having a two layer AI, the first dealing with the tactical situation (movement in the next few loops of the game logic concentrating on avoiding other aircraft and the ground, working out what is the best way to orientate towards the waypoint / target, rotating turrets and firing weapons ... oh and crashing which is fairly simple AI occasionally involving parachutes) and a higher level AI dealing with the 'strategic' situation (choosing a target or the next waypoint, responding to being attacked, deciding whether to run for it if damaged, checking if there is any fuel left, etc). Despite taking a while to get right (and it still needs some final polishing) this two layer approach (coupled with a third, squadron level logic) really made the organisation of the AI pretty easy to conceptualise and break down. While the AI is the big overhead in my code I can now effectively handle dogfights between anything up to (and beyond) 80 aircraft without the lights starting to flicker and brown-out.

If performance is poor there are two things that can be done,

  • Simplify the AI for out of sight objects (simplify collision detection or even ignore it, don't actually fire weapons and track projectiles but just apply damage to the target, etc) - if the player cannot see the AI being more stupid then it isn't really a problem (although initially I did have problems with quick switches from one unit to another distant unit resulting in the player admiring aircraft happily flying upside down in formation ... tweaks to the simple AI and the application of a few loops worth of complex AI during the switch helped there).
  • Only process each unit's AI every few game loops (I actually have a game setting where the AI can be applied for every unit during each and every game loop ... which is fine for higher end machines, or every second, third, fourth, etc loop ... meaning that I can effectively cut the processor overhead by half, etc ... at the cost of an increasing number of poor collision detection decisions, etc as the frequency of the AI being applied for each unit drops). Having something playable, but not as elegant on a lower end machine is in my view better than having the Rolls Royce solution that is unplayable due to the game effectively freezing up.

?

Jon.
_______________________________________
Legends from the Lost Realms


Dynamic Maneuver Generation

Thanks for the information. So would there be a list of pre-programmed maneuvers and the best one would be picked?

No. As I described, you set up flavors of maneuver, and you dynamically move the craft along a similar path - but you're not playing a pre-canned animation.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

maneuver based AI can be too predictable if it doesn't change quickly enough. 2 seconds into a maneuver, I know what the enemy is doing, and can position myself for the kill. Real pilots don't assess the situation, select a maneuver, then blindly execute it, then reassess the situation. The situation is reassessed continuously, and maneuvers are adjusted appropriately on a continual basis. For this reason, i prefer a more dynamic AI that works at a lower level, simply dictating turn and accel rates, vs entire maneuvers. a layered strategy is then applied: 1. collision avoidance. 2. evasive maneuvers. 3. maneuver for kill. The ai then degenerates to simple rules like "badguy left, turn left", "badguy above, climb", etc. maneuvers can then be layered on top of this: "badguy behind and above, do Immelmann". this would kick off a "script" that would do a half loop followed by a half roll. but you don't just execute the "script". each "frame" you assess the situation. if you should continue the Immelmann, you continue running the "script", if not, you stop the Immelmann and do something else. the situation should be re-assessed, and the maneuver changed if needed, at least once per second to be sufficiently responsive. And an experienced pilot will notice that one second lag in decision making on the part of the AI. A good pilot will take advantage of it to get a leg up on the AI. A really good pilot will be disgusted by it as being too slow to react to the player in a timely manner. A full one second head start on your opponent is WAY too much of an advantage for a really good pilot.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement