2017-05-11 3 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(); 
      } 
     } 
} 

問題は、彼は非常に迅速に前後に回転し続けていることですが、私は私が欲しいtehの所望の効果を得ることができません。動作するはず

答えて

0

は0

編集にNavMeshエージェントのの角速度を設定してみてください 代わりのエージェントをやって:

// 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

これは、私はそれをどのように処理したかです。やめる();とエージェント。私は単に速度を0に設定し、transform.Rotateを使用して文字を回転させます。