【问题标题】:NavMesh Agent override rotationNavMesh 代理覆盖旋转
【发布时间】:2017-05-11 23:08:04
【问题描述】:

我有敌人使用NavMesh Agent 巡逻到不同的航路点,我希望在敌人到达下一个航路点时与该航路点具有相同的旋转。 代码如下:

void Update ()
{
    if (agent.remainingDistance < 0.1)
        {
            // tried to stop the agent so I can override it's rotation, doesn't work
            agent.Stop();
            // Give him the desired rotation
            transform.rotation = wayPoints[curretPoint].rotation;

            if (curretPoint < wayPoints.Length -1)
            {
                curretPoint++;
            }
            else 
            {
                curretPoint = 0;
            }
            // make him wait for a fixed amount of time
            patrolTimer += Time.deltaTime;
            if (patrolTimer >= patrolWait)
            {
                patrolTimer = 0;
                agent.SetDestination (wayPoints[curretPoint].position);
                agent.Resume ();
            }
        }
}

问题是他一直在快速地来回旋转,我无法得到我想要的效果。

【问题讨论】:

    标签: c# unity3d navmesh


    【解决方案1】:

    尝试将 NavMesh Agent 的 Angular Speed 设置为 0。

    编辑:

    应该可以的:

        // make him wait for a fixed amount of time
        patrolTimer += Time.deltaTime;
        if (patrolTimer >= patrolWait)
        {
            if (curretPoint < wayPoints.Length -1)
            {
                curretPoint++;
            }
            else 
            {
                 curretPoint = 0;
            }
            patrolTimer = 0;
            agent.SetDestination (wayPoints[curretPoint].position);
            agent.Resume ();
        }
    

    【讨论】:

    • 不,这没有任何作用。
    【解决方案2】:

    我是这样处理的: 而不是做 agent.Stop();和 agent.Resume();我只是将它的速度设置为 0 并使用 transform.Rotate 来旋转角色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-10
      相关资源
      最近更新 更多