飞行游戏AI算法?

发布于 2024-09-26 14:06:25 字数 196 浏览 10 评论 0原文

大家好,

我正处于我的一个爱好项目的设计阶段。我将开发一款 3D 空战游戏。 (受到 HAWX 的启发)。 但我想知道人工智能如何作用于敌方飞船?我猜想,它们不会像 FPS 游戏那样沿着路径移动(在图表上查找路径)。 我可以使用什么样的算法来移动敌方飞船? 我可以使用任何人工智能库吗?

注意:我使用irrlicht引擎,C++作为我的开发环境。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼睛不忧郁 2024-10-03 14:06:25

寻找截取点的简单答案...

在任何时间点,做出直线假设。您和您的目标以固定速度直线行驶。因此,您可以从目标中减去您的位置和运动,并使用目标的相对位置和速度。

一个有趣的时间点是当你的目标尽可能接近(在那条线上)时——那条线上最近的点。 IIRC,可以用矢量点积来计算...

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

假设我是对的,此时目标路径与从你到目标的线成直角(与它和你的运动之间的角度不同) )。你可以使用三角学得到一个等价的答案(点积与余弦相关),我什至使用联立方程法一次计算出它(不知道更好),对于我多年前开始但从未完成的 2D 游戏(想想 oid/推力式旋转推力飞船与重力之间的战斗)。

由此,您可以确定最近点的位置以及距离。

计算当前速度和方向的微小变化的时间,并且您可以针对不久的将来的拦截迭代优化。当然,最小化 t 会带来 t 可能进一步回到过去的可能性 - 逃跑!也许最小化 t 平方会更好,但这样你就会遇到其他复杂情况 - 如果敌人就在你身后,你真的想放慢速度吗?

不管怎样,这对于一枚简单的导弹来说可能已经足够了,但当然在空战中用处不大。我对此的印象更像是一种模拟实时国际象棋,大多数时候你看不到棋盘的大部分内容。显然,你不能将其最小化,因此你需要一个更高级别的移动模型,而不仅仅是操纵杆和其他控制设置。在开始为其设计人工智能引擎之前,需要对基于人类经验的策略进行大量研究。

不过,为了利用地形的掩护,你可能可以做一些更简单的事情。基于图形的路径查找器很可能与绘制穿过山谷的路线相关。在 2D 中进行大部分寻路,并调整地图相对平滑的变化“谎言”,以确保你不会直接飞入悬崖。

也许您需要一个包含不同类型目标和策略的系统,以及在它们之间进行权衡和选择的方法。距离目标很远时,你更有可能试图躲在隐蔽处,而不是靠近目标。当你的尾部有导弹时,它将优先于你可能采取的任何进攻行动,依此类推。

顺便说一句 - 这些都不是来自游戏开发的真实经验(而且我当然从来没有成为任何描述的飞行员),所以对待它是模糊的建议,可能不会成功。请注意,我的 2D 游戏从未完成的一个原因是,尝试编写 AI 代码一开始非常有趣,后来却令人沮丧 - 当你对 AI 的最佳尝试能够击败你的唯一方法是通过拥有数倍的船只和无限的弹药供应。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文