防止实体在头顶射击游戏中相互堆叠

发布于 2024-12-02 04:14:37 字数 225 浏览 2 评论 0原文

我正在开发一款头顶射击游戏,随着时间的推移,当我在竞技场周围绕圈移动时,敌人会开始互相堆叠,直到成为一大堆单位。它最终看起来很愚蠢。

人工智能非常简单和基本:找到玩家,向他移动,如果他在范围内则攻击他。

将它们推开以使它们不会都出现在同一个地方的最佳方法是什么?我认为蜂拥而至有点过大(而且可能过于密集,因为屏幕上一次会出现 100-200 个敌人)。

有想法吗?

谢谢!

I'm working on an overhead shooter and what happens is, over time, as I move in circles around the arena, the enemies will begin to stack on top of each other until they're one giant stack of units. It ends up looking pretty silly.

The AI is pretty simple and basic: Find the player, move towards him, and attack him if he's in range.

What's the best way to push them away from each other so that they don't all end up on the same spot? I think flocking is a bit overkill (and probably too intensive since I'll have 100-200 enemies on the screen at a time).

Ideas?

Thanks!

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

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

发布评论

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

评论(1

记忆で 2024-12-09 04:14:37

您可以采用以下几种不同的方法来解决此问题:

  1. 您可以为每个单元定义一个势场,将“高度”或“坏度”与地图上的每个位置相关联。每个单位都以一种试图最小化其潜力的方式移动,也许是朝着将其一步移动到最低潜力的方向迈出一步。您可以定义势函数,使其向玩家倾斜,导致所有单位尝试移动到玩家,但也可以在现有单位周围非常高,导致单位避免相互碰撞。这是一个非常强大的框架,一直在人工智能领域得到利用;一个著名的例子是它在 Berkeley Overmind AI for StarCraft 中的使用,最终赢得了 AI StarCraft 竞赛。如果你确实采用这种方法,你可能会调整潜在的功能,让人工智能以许多其他有趣的方式表现,并且可以轻松支持集群。我个人认为这是最好的方法,因为它是最灵活的。这也将是更先进的寻路模型的一个很好的起点。有关人工智能潜在领域的非常实用介绍,请查看这个网站。对于势场及其应用的严格数学介绍,您可能需要查看本文使用势场调查不同的人工智能方法。

  2. 如果您为每个敌人定义一个边界圆,您可以通过防止任何两个单位位于彼此两个半径距离内来明确禁止这些单位堆叠在一起。每当两个单位距离太近时,你都可以阻止其中一个单位移动,或者可以让它们彼此施加力量以将它们分开。当两个单位相互碰撞时,您可以选择一个随机力矢量应用于每个单位,以尝试将它们分开。与潜在领域相比,这是一个更黑客且不太优雅的解决方案,但如果您需要启动并运行某些东西,这绝对是一个可行的选择。

  3. 您可以选择玩家周围的一组单位尝试移动的点,然后让每个单位随机选择其中一个目标点移动到。这将导致单位在玩家周围以环形(或您想要的任何形状)更薄地分布,从而避免您迄今为止看到的巨大质量。同样,这比使用势场要优雅得多,但如果您的目标是让某些东西快速工作,那么这是您可以尝试的另一种快速技巧。

希望这有帮助!

Here are a few different approaches you could take to solving this problem:

  1. You could define a potential field for each unit that associates a "height" or "badness" to each location on the map. Each unit moves in a way that tries to minimize its potential, perhaps by taking a step in the direction that moves it to the lowest potential that it can in one step. You could define the potential function so that it slopes toward the player, causing all units to try to move to the player, but also be very high around existing units, causing units to avoid bumping into one another. This is a very powerful framework that is exploited all the time in AI; one famous example is its use in the Berkeley Overmind AI for StarCraft, which ended up winning an AI StarCraft competition. If you do adopt this sort of approach, you could probably then tweak the potential function to get the AI to behave in many other interesting ways, and could easily support flocking. I personally think that this is the best approach to take, as it's the most flexible. It also would be a great starting point for more advanced pathfinding models. For a very good and practical introduction to potential fields for AI, check out this website. For a rigorous mathematical introduction to potential fields and their applications, you might want to check out this paper surveying different AI methods using potential fields.

  2. If you define a bounding circle for each enemy, you could just explicitly disallow the units from stacking on top of each other by preventing any two units from being within two radii's distance of one another. Any time two units got too close, you could either stop one of them from moving, or could have them exert forces on one another to spread them apart. When two units bump into each other, you could just pick a random force vector to apply to each unit to try to spread them apart. This is a much hackier and less elegant solution than potential fields, but if you need to get something up and running it's definitely a viable option.

  3. You could choose a set of points around the player that the units try to move toward, then have each unit randomly choose one of those target points to move to. This would cause the units to spread more thinly in a ring (or whatever shape you'd like) around the player, avoiding the huge masses that you've seen so far. Again, this is way less elegant than using potential fields, but it's another quick hack you could experiment with if your goal is to get something working quickly.

Hope this helps!

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