0

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

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

4

2 回答 2

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 ();
    }
于 2017-05-12T10:14:24.243 回答
0

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

于 2017-05-12T11:59:06.350 回答