【发布时间】:2017-01-25 16:05:07
【问题描述】:
我的问题是,每当它试图向当前航路点移动时,它都会面临奇怪的方向并且没有完全遵循路径。
IEnumerator FollowPath() {
Vector3 currentWaypoint = path[0];
while (true) {
//transform.LookAt (currentWaypoint);
if (transform.position == currentWaypoint) {
PathRequestManager.RequestPath(transform.position,target.position,OnPathFound);
targetIndex=0;
targetIndex ++;
//Debug.Log(currentWaypoint);
if (targetIndex >= path.Length) {
targetIndex =0;
path = new Vector3[0];
//yield break;
}
currentWaypoint = path[targetIndex];
}
transform.LookAt (currentWaypoint);
transform.position = Vector3.MoveTowards(transform.position,currentWaypoint,speed * Time.deltaTime);
yield return null;
}
}
目前正在使用 * 寻路。完整的源代码在这里:https://github.com/SebLague/Pathfinding
到达当前航点时,随机改变方向或随机朝向,不经过下一个航点。 (Screenshot)
【问题讨论】:
标签: c# unity3d artificial-intelligence path-finding a-star