unity3d Unity 2D - A* 寻路我如何让求知者避开其他求知者?

dkqlctbz  于 2023-01-31  发布在  其他
关注(0)|答案(2)|浏览(153)

正在用Aron Granberg A* 寻路工具制作一个Unity 2D自上而下的游戏。有人知道我如何让带着探索者脚本的敌人互相躲避吗?目前他们会互相攻击,我希望能避免这种情况。
在下面的照片中,你可以看到绿色线显示了AI目标设定者的目标。它正确地跟随着玩家,但右边的立方体试图直接穿过红色立方体。我该如何改变它,使寻找者避开彼此,但仍然跟随着玩家?

public class AIDestinationSetterHyperius : VersionedMonoBehaviour {
    /// <summary>The object that the AI should move to</summary>
    public Transform target;
    IAstarAI ai;

    public void OnEnable () {
        target = GameObject.FindWithTag("Player").transform;
        ai = GetComponent<IAstarAI>();

        if (ai != null) ai.onSearchPath += Update;
    }

    public void OnDisable () {
        if (ai != null) ai.onSearchPath -= Update;
    }

    /// <summary>Updates the AI's destination every frame</summary>
    public void Update () {
        if (target != null && ai != null) ai.destination = target.position;
    }
}
zvokhttg

zvokhttg1#

如果我没有理解错的话,看起来你需要local avoidance,它只在专业版的包中可用。

uidvcgyl

uidvcgyl2#

我在合一中是个菜鸟,所以我的方法可能不好。不久前我设法让这个工作。所以我把求知者层加入到应该避免的列表中,然后修改了脚本中的A* 扫描障碍物,并使扫描不仅在开始,但一定的速度。实验与扫描速度,直到它成为精简的性能,但仍然做它的工作。我的项目很小,所以我没有问题,帧速率没有下降。

相关问题