NavMesh Agent 覆盖旋转

NavMesh Agent override rotation

我有敌人巡逻到不同的 waypoints 使用 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 ();
            }
        }
}

问题是他来回旋转的速度很快,达不到我想要的效果。

尝试将 NavMesh Agent 的 Angular 速度 设置为 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 ();
    }

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