【问题标题】:Unity Multiple navmesh agents .Unity 多个导航网格代理。
【发布时间】:2017-09-11 22:08:22
【问题描述】:

你好,我正在开发一款 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);

            }

        }
    }
}

【问题讨论】:

    标签: c# unity3d artificial-intelligence


    【解决方案1】:

    代理将尽可能靠近该位置。既然你告诉他们两个都去同一个位置,他们就会尽可能地靠近。您可能想要增加停止距离或将 random.insideunitsphere 添加到 hit.point,使它们看起来更像一个组

    【讨论】:

    • 你能举例说明吗
    猜你喜欢
    • 1970-01-01
    • 2021-02-26
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多