unity3d - 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);
}
}
}
}
和我的兔子物品的照片;)
解决方案
停止距离应 > 0
推荐阅读
- amazon-web-services - 将 Amazon SQS 与 ELB 连接
- deep-learning - 在多个数据集上训练深度学习模型时,最好将所有数据集连接起来并打乱它,还是按顺序训练数据集?
- zsh - zsh:找不到命令:闪电战
- python - 为基于日志的等高线选择颜色条刻度的位置
- audio - 在运行 ffmpeg 时添加、删除和调整过滤器
- android - NativeScript JS:缺少带有 resourceID 的图像 - 远程图像 API
- c++ - 结构化绑定在 VS 2019 中不起作用
- c# - UWP FullTrustProcessLauncher 在启动时给出“找不到元素”异常
- tensorflow - 可以在 Firebase 上部署使用 tensorflow-probabilities 层的 tensorflow 模型吗?
- html - 修复了在调整窗口大小时页脚滚动到正文中的问题