首页 > 解决方案 > Unity NavMeshAgent 未达到目标 - 移动

问题描述

我创建了一个简单的场景,现在我正试图让兔子移动到平面上的鼠标单击位置。

所以我给兔子添加了一个刚体、一个导航网格代理和一个简单的“寻路”脚本。

平面网格渲染器设置为“Navigation Static”、“Generate OffMeshLinks”和“Walkable”

现在,一旦兔子接近给定的目的地,它就不会停下来,而是在目的地周围的一个非常小的圆圈中“跑来跑去”。

这是我的脚本

using UnityEngine;
using UnityEngine.AI;

public class Pathfinding : MonoBehaviour {

private NavMeshAgent agent;
private Animator animator;

// Use this for initialization
void Start() {
    agent = GetComponent<NavMeshAgent>();
    animator = GetComponent<Animator>();
}

// Update is called once per frame
void Update() {
    RaycastHit hit;

    if(Input.GetMouseButtonDown(0)) {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if(Physics.Raycast(ray, out hit)) {
            agent.SetDestination(hit.point);
            animator.SetInteger("AnimIndex", 1);
            animator.SetBool("Next", true);
        }
    }
}
}

和我的兔子物品的照片;)

在此处输入图像描述

标签: unity3d

解决方案


停止距离应 > 0


推荐阅读