远离目标

发布于 2024-10-24 15:52:21 字数 578 浏览 2 评论 0原文

我有一个数组,其中填充了带有标签 Enemy 的所有对象。当一个敌人靠近另一个敌人时,它必须远离该敌人或绕过它。

这就是我现在所拥有的:

foreach(Transform enemy in enemies){
    if(enemy == this.transform) continue;

    enemyPos = enemy;
    float enemyDistance = Vector3.Distance(enemy.transform.position, transform.position);

    if(enemyDistance < 8){
        transform.RotateAround (enemyPos.position, Vector3.up, 360 * Time.deltaTime);
    }
}

如果敌人彼此距离足够近,他们就会围着对方转。还尝试使用 2 个立方体触发器,当敌方物体接触其中一个立方体时,立方体敌人将旋转远离它。也尝试了不同的角度。 但运气不好:(

我仍在努力寻找解决方案。但如果您对此有更好的想法,非常感谢您的帮助:)

提前致谢!

I have an array which is filled with all the objects with the tag Enemy. When one enemy comes close to an other enemy, it has to stay away from that enemy or go around it.

This is what I have now:

foreach(Transform enemy in enemies){
    if(enemy == this.transform) continue;

    enemyPos = enemy;
    float enemyDistance = Vector3.Distance(enemy.transform.position, transform.position);

    if(enemyDistance < 8){
        transform.RotateAround (enemyPos.position, Vector3.up, 360 * Time.deltaTime);
    }
}

If enemies come close enough to each other, they will circle around each other. Also tried to use 2 cube triggers for when an enemy object touches one of the cubes, the cubed enemy wil rotate away from it. Also tried different angles.
But no luck :(

I am still trying to find a solution. But if you have a better idea about this, your help is much appreceated :)

Thanks in advance!!!

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

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

发布评论

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

评论(2

我是男神闪亮亮 2024-10-31 15:52:21

您有多个移动的物体,其中一些可能会妨碍其他物体。我建议您推迟移动所有前面有移动障碍物的物体。当所有自由移动的对象都被移动后,然后尝试通过重复该过程来移动所有其他对象,因为在此过程中某些对象可能会变得自由。您实际上是循环遍历尚未移动的对象的列表,直到列表中没有更改为止。

如果您没有找到任何新的自由移动物体,请按照您的意愿处理其余的物体。我建议您尝试仅为其中之一找到替代路线,然后重复上述过程。可能当一个物体脱离时,所有其他物体也都脱离了。您可以对其余卡住的物体重复第二个过程。

You have several moving objects, and some of them may stand in the way of other objects. I would propose that you defer moving of all those objects that have a moving obstacle in front of them. When all free-moving objects are moved then try to move all other, by repeating the procedure, because in the process some objects might become free. You essentially loop through list of not-yet-moved objects until there is no change in the list.

If you don't find any new free-moving objects then deal with the rest as you like. I would suggest that you try find alternative route only for one of them, and then repeat the procedure above. It might be that when one object is unstuck then all others are unstuck as well. You may repeat this second procedure for the rest of stuck objects.

清眉祭 2024-10-31 15:52:21

以下文章可以帮助您。

简而言之,当你的智能体低于给定距离时,他们会相互“排斥”。这就是羊群中的“分离”概念。真正有趣的是,您可以根据距离进行轮换(即,另一个非常接近的代理意味着您必须用力转动),并且您可以与多个代理进行交互。

在同一站点中,可以帮助您搜索播放器。结合这两种方法,你的代理会尝试抓住玩家,同时避开其他代理。

问候
纪尧姆

The following article could help you.

In short, your agent are "repulsing" each other when they are under the given distance. This is the "separation" concept in the flock. What is really interesting is that you can have a rotation that depends on the distance (ie another agent very near mean that you have to turn hard) and that you can interact with more than one agent.

in the same site, this can help you search the player. Combien the two method, and you have agents that try to catch the player while avoiding other agents.

regards
Guillaume

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