Flight game AI algorithm?
Asked Answered
N

1

6

Greetings all,

I am in the designing phase of one of my hobby project.I am going to develop an 3D air-combat game . (inspired by HAWX). But I am wondering how the AI works for enemy crafts ? I guess ,they do not move along a path (path finding on a graph)as in FPS games . What kind of algorithms can I use for enemy craft movement? Are there any AI libraries I can use for this?

Note: I use irrlicht engine,C++ as my development environment.

Nutty answered 4/10, 2010 at 1:44 Comment(0)
E
5

A simple answer for finding an interception point...

At any point in time, make a straight-lines assumption. You and your target are travelling in straight lines at fixed speeds. Therefore, you can subtract your position and motion from your targets, and work with the targets relative position and velocity.

An interesting point in time is when your target is as close (on that line) as it will ever be - the closest point on that line. IIRC, that can be calculated with vector dot products...

      P . V
t = - -----
      V . V

Assuming I got that right, at this point the targets path is at a right angle to the line from you to the target (NOT the same as the angle between its and your motions). You could get an equivalent answer using trigonometry (a dot product is related to the cosine), and I even worked it out (not knowing better) using a simultaneous equations method once, for a 2D game that I started but never finished many years ago (think combat between oids/thrust style rotate-and-thrust ships with gravity).

From this, you can determine where that closest point is and how far it is.

Calculate this time for small variations on your current speed and direction and you can iteratively optimise for a near future interception. Of course minimising t brings in the possibility that t might get ever further into the past - running away! Maybe minimising t squared would be better, but then you have other complications - if the enemy is right behind you, do you really want to slow down?

Anyway, this is probably enough for a simple guided missile, but of course very little use in a dogfight. My impression of that is more like a kind of analogue real-time chess where you can't see most of the board most of the time. You can't minimax that, obviously, so you need a higher level model of what the moves are than just joystick and other control settings. That'll need a fair bit of research into human-experience based tactics before you start designing an AI engine for it.

For exploiting cover in terrain, though, you can probably do something much simpler. A graph-based path-finder may well be relevant to plotting a route through valleys. Do most of the pathfinding in 2D, and tweak the map relatively-smooth-variations "lies" to ensure you don't fly straight into a cliff.

Probably you need a system of different types of goals and tactics, with a way of weighting and choosing between them. A long way from your target, your more likely to try to stay in cover than when you get closer. When you have a missile on your own tail, that'll take priority over any offensive actions you might take, and so on.

BTW - none of this is from real experience of games development (and I've certainly never been a pilot of any description) so treat it is vague suggestions that may not pan out. And beware - one reason that 2D game of mine never got finished was because trying to work out AI code was at first so interesting, then later so frustrating - it's so annoying when the only way your best attempt at an AI can beat you is by having many times more ships and an infinite supply of ammo.

Enstatite answered 4/10, 2010 at 3:50 Comment(4)
Hi , steve thanks for the tips.Actually my question is not specific.I think I have to keep a state-machine for enemy states. (eg: attack bulidings,attack player,chase player,defence from player missles..etc). And depend on the state the algorithm should be changed.I wonder how they implemented AI in games like H.A.W.X!Nutty
I don't think that you can ignore the absolute velocity. The medium (air) is at rest and has a great influence upon how you can maneuver.Carrizales
@Carrizales - The closest point calculation assumes a constant velocity. For choosing minor variations for the optimisation, it makes sense to take into account approximate limits of the simulated aircraft, but this is for setting a goal, not deciding what the aircraft will actually achieve. Deciding the real performance of the aircraft is the job of the physics engine, not the AI engine. A more sophisticated AI may well need a complex model of the physics, but this isn't about physics - it's about AI, and very simple AI at that.Enstatite
@umanga - I'm sorry, but I've never played HAWX. You probably will need a state machine for what you describe, but there's little advice I can give on that - the implementation will depend on the specific details.Enstatite

© 2022 - 2024 — McMap. All rights reserved.