首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NavMesh代理覆盖旋转

NavMesh代理覆盖旋转
EN

Stack Overflow用户
提问于 2017-05-11 23:08:04
回答 2查看 4.6K关注 0票数 0

我有敌人使用NavMesh Agent对不同的路径点进行巡逻,我希望当敌人到达下一个方向点时,有与那个路径点相同的旋转。以下是代码:

代码语言:javascript
复制
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 ();
            }
        }
}

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-05-12 10:14:24

尝试将代理的角速度设置为0。

编辑:

这应该是可行的:

代码语言:javascript
复制
    // 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 ();
    }
票数 0
EN

Stack Overflow用户

发布于 2017-05-12 11:59:06

这就是我处理它的方式:我没有执行agent.Stop();和agent.Resume();我只是将其速度设置为0,并使用transform.Rotate旋转字符。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43926950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档