【发布时间】:2023-01-27 09:45:14
【问题描述】:
使用 Aron Granberg A* 寻路资产开发 Unity 2D 自顶向下游戏。有谁知道我怎样才能让带有搜索者脚本的敌人互相避开?目前他们会聚在一起,我想避免这种情况。
在下面的照片中,您可以看到显示 AI Destination Setter 目标的绿线。它正确地跟随玩家,但右边的立方体正试图直接穿过红色立方体。我怎样才能改变它,让探索者互相避开但仍然跟随玩家?
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;
}
}
【问题讨论】:
标签: unity3d path-finding