NavMesh代理覆盖旋转

时间:2017-05-11 23:08:05

标签: c# unity3d navmesh

我有敌人使用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 ();
            }
        }
}

问题是他不停地来回旋转,我无法获得我想要的效果。

2 个答案:

答案 0 :(得分:0)

尝试将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 ();
    }

答案 1 :(得分:0)

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

相关问题