2017-05-11 57 views
0

我有敵人用不同的航路點巡邏,使用NavMesh Agent當敵人到達下一個航點並與航點相同時,我需要它。 下面是代碼:NavMesh代理覆蓋旋轉

void Update() 
{ 
    if (agent.remainingDistance < 0.1) 
     { 
      // tried to stop the agent so I can override it's rotation, doesn't work 
      agent.Stop(); 
      // Give him the desired rotation 
      transform.rotation = wayPoints[curretPoint].rotation; 

      if (curretPoint < wayPoints.Length -1) 
      { 
       curretPoint++; 
      } 
      else 
      { 
       curretPoint = 0; 
      } 
      // make him wait for a fixed amount of time 
      patrolTimer += Time.deltaTime; 
      if (patrolTimer >= patrolWait) 
      { 
       patrolTimer = 0; 
       agent.SetDestination (wayPoints[curretPoint].position); 
       agent.Resume(); 
      } 
     } 
} 

的問題是,他一直非常迅速地來回旋轉,我無法得到我想要格蘭預期的效果。

回答

0

嘗試角速度導航網格代理設置爲0

編輯:

這應該工作:

// make him wait for a fixed amount of time 
    patrolTimer += Time.deltaTime; 
    if (patrolTimer >= patrolWait) 
    { 
     if (curretPoint < wayPoints.Length -1) 
     { 
      curretPoint++; 
     } 
     else 
     { 
      curretPoint = 0; 
     } 
     patrolTimer = 0; 
     agent.SetDestination (wayPoints[curretPoint].position); 
     agent.Resume(); 
    } 
+0

不,沒有做任何事情。 – Abdou023

+0

我編輯了我的帖子,試試這個。 – Woltus

+0

這工作完美。謝謝。 – Abdou023

0

這是我如何處理它: 而不是做代理的。停止();和agent.Resume();我只需將其速度設置爲0,然後使用transform.Rotate旋轉角色。