2
我的問題是,無論何時它試圖朝着當前的航點移動,它都會面臨奇怪的方向,並且完全不遵循路徑。AI在遇到航點時面臨奇怪的方向UNITY
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)
我忘了告訴它,當沒有方向,或者位置是靜態時,它會轉到另一個路點。但是當我向他所看到的方向添加方向時,它會面臨奇怪的方向約10秒,然後轉到下一個航點或有時不會轉到下一個航點,因爲他正在查看該當前點。 –
擺脫'targetIndex = 0;' – maksymiuk
我嘗試了你的建議,但它在到達航點後仍然面臨奇怪的方向。雖然我不知何故得到了錯誤來自哪裏。它來自動畫和這行代碼「transform.LookAt(currentWaypoint);」。我曾嘗試刪除動畫,並以某種方式進入下一個航點。我怎樣才能解決這個問題?該動畫僅具有靜態運行。所以它沒有空閒或任何東西,只有運行動畫。 –