所以,我有一個球和一些障礙物,它們不允許球移動到目標。球正在射擊子彈,每次射擊后我都在檢查球是否可以到達目標。我需要球保持在起始位置,直到路徑暢通。不幸的是,即使有一些障礙在路上,球也會繼續移動,直到反擊它們。
這就是我試圖做的:`
private void TryReachTheTarget()
{
if (NavMesh.CalculatePath(_agent.transform.position, _target.position, NavMesh.AllArea s, _path) && _path.status == NavMeshPathStatus.PathComplete)
{
_agent.SetPath(_path);
}
}
`
uj5u.com熱心網友回復:
您可以嘗試找到一條路徑并回傳是否成功。檢查路徑有點慢,但只要你不每秒拍攝數百次,這應該沒問題。
// your agent
public NavMeshAgent agent;
// variable for storing the path
private NavMeshPath navMeshPath = new NavMeshPath();
// tries to find a path, and returns true if successful
public bool CanReachArea(Vector3 target) {
return agent.CalculatePath(target, navMeshPath) && navMeshPath.status == NavMeshPathStatus.PathComplete;
}
uj5u.com熱心網友回復:
解決方案似乎非常簡單。我所需要的只是從目標上取下 Obstacle 組件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/533275.html
標籤:unity3d