【问题标题】:NavMeshAgent nextPosition and destination change on enable启用时 NavMeshAgent nextPosition 和目标更改
【发布时间】:2021-06-05 15:39:24
【问题描述】:

我有一个回合制游戏,可以在 NavMeshAgents(选中时)和 NavMeshObjects(未选中时)之间切换

我只是使用 NavMeshAgent 导航路径,然后手动导航,因此我将 updatePosition 和 updateRotation 永久设置为关闭

当我选择代理时,如果我在启用代理之前检查代理的 nextPosition 和目的地,它们都与我的游戏对象相同,但是一旦启用代理,nextPos 和 dest 在 z 上都会跳大约 2轴。

奇怪的是,我无法通过直接设置或通过 SetDestination 或 Warp 函数手动将 nextPosition 或目的地更改为正确的值。所以我最终的导航路径从错误的位置开始。

下面的代码用 cmets 描述了我所看到的,我目前使用的是统一版本 2020.2.7f1,但尝试了几个 2.x 版本

    protected void SetCharacterNavAgentOn()
    {
        obstacle.enabled = false; // nextposition & destination are correct at this point
        agent.enabled = true; // but now they have been offset
        agent.nextPosition = gameObject.GetComponent<Rigidbody>().position; // this doesn't change the nextPosition
        agent.SetDestination(gameObject.GetComponent<Rigidbody>().position); // this doesn't change the destination
        bool isSuccessfull = agent.Warp(gameObject.GetComponent<Rigidbody>().position); // this doesn't change the nextPos or destination despite returning true
        gameObject.GetComponent<BoxCollider>().enabled = false;
        gameObject.GetComponent<Rigidbody>().isKinematic = true;
    }

任何帮助都将不胜感激,可能是一个错误,但我已经挖掘并无法找到其他人遇到相同问题的任何示例。

【问题讨论】:

    标签: unity3d navmesh


    【解决方案1】:

    在此线程中为正在寻找 https://forum.unity.com/threads/disabling-navmesh-obstacle-and-enabling-navmesh-agent-on-unit-causes-jumping-before-moving.1010998/ 的其他人找到答案

    基本上这是一个计时的事情,在启用代理之前需要时间重新烘焙网格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-06
      • 2021-07-27
      • 2010-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多