开发者

Flight game AI algorithm?

开发者 https://www.devze.com 2023-01-18 09:28 出处:网络
Greetings all, I am in th开发者_C百科e designing phase of one of my hobby project.I am going to develop an 3D air-combat game . (inspired by HAWX).

Greetings all,

I am in th开发者_C百科e 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消