2017-09-11 33 views
0

こんにちは、私はRTSゲームに取り組んでいますので、私は1人のミニオンをコントロールしますが、もう1人のミニオンを追加してポイントに行くように命令してから、http://imgur.com/a/uHwjGのように見ます。 手先が移動するためのコードはこれです:Unity複数のnavmeshエージェント。

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.AI; 

public class moveTest : MonoBehaviour { 

    NavMeshAgent navAgent; 



    // Use this for initialization 
    void Start() { 
     navAgent = GetComponent<NavMeshAgent>(); 


    } 

    // Update is called once per frame 
    void Update() { 

     move(); 

    } 
    void move() 
    { 
     RaycastHit hit; 
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 
     if (Input.GetMouseButtonDown(1)) 
     { 
      if (Physics.Raycast(ray, out hit, 1000)) 
      { 
       navAgent.SetDestination(hit.point); 

      } 

     } 
    } 
} 

答えて

2

エージェントは、それが位置することができる限り近くなります。あなたは両方とも同じポジションに向かうと言っているので、彼らは可能な限り接近します。停止距離を伸ばしたり、hit.pointにrandom.insideunitsphereを追加してグループのように見えるようにすることができます

+0

例のように説明できますか –

関連する問題