Unity多个navmesh代理。

时间:2017-09-11 22:08:23

标签: c# unity3d artificial-intelligence

你好我正在研究一个RTS游戏,所以我将控制超过1个小兵,但是我想要并添加另一个小兵并指挥他们两个他们去到这一点然后他们看着对方这样http://imgur.com/a/uHwjG 。 移动小兵的代码是:

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);

            }

        }
    }
}

1 个答案:

答案 0 :(得分:2)

代理人将尽可能接近该职位。既然你要告诉两个人去同一个位置,他们会尽可能地向前推进。您可能希望增加停止距离或在hit.point中添加random.insideunitsphere,使它们看起来更像一个组