首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Animator.SetBool()破坏NavMeshAgent

Animator.SetBool()破坏NavMeshAgent
EN

Stack Overflow用户
提问于 2020-02-12 13:49:32
回答 1查看 180关注 0票数 0

我有两个动画设置为我的僵尸。一种是当僵尸不知道播放器时的行走动画,另一种是当僵尸意识到播放器时运行的动画。

我还有一个导航网,每个僵尸都有一个NavMeshAgent组件。

该步行动画工作良好,并坚持在网格的边界。但是当僵尸意识到时,我将使用Animator.SetBool()函数将其转换为正在运行的动画。

转换打破了代理的意义,因为它只是在向玩家运行后继续离开网格。

我是团结公司的新手,所以任何帮助都是非常感谢的。

编辑

下面是代码:

代码语言:javascript
复制
private void Update()
{
        if(isAware)
        {
            navAgent.SetDestination(player.position);
            animator.SetBool("Aware", true);
            navAgent.speed = chaseSpeed;
        }
        else
        {
            SearchPlayer();
            Wander();
            animator.SetBool("Aware", false);
            navAgent.speed = wanderSpeed;
        }
    }

    public void SearchPlayer()
    {
        if (Vector3.Angle(Vector3.forward, transform.InverseTransformPoint(player.position)) < view / 2f)
        {
            if(Vector3.Distance(player.position, transform.position) < viewDist)
            {
                OnAware();
            }
        }
    }

    public void OnAware()
    {
        isAware = true;
    }

    /*
     * Create random points on the Navigation Mesh for the zombies to aimlessly wander to
     */
    private Vector3 WanderingPoint()
    {
        Vector3 randomPoint = (Random.insideUnitSphere * 4f) + transform.position; // Create a random point in a sphere surrouding the zombie
        NavMeshHit navHit;
        NavMesh.SamplePosition(randomPoint, out navHit, 7f, -1); //Get nearest point on the Navigation Mesh to the random point generated in the sphere around the zombie so that it stays within the mesh

        return new Vector3(navHit.position.x, transform.position.y, navHit  .position.z); 


    }

    private void Wander()
    {
        if(Vector3.Distance(transform.position, wanderPoint) < 2f) //Create new Wandering Point when zombie reaches the current wandering point
        {
            wanderPoint = WanderingPoint();
        }
        else
        {
            navAgent.SetDestination(wanderPoint);
        }
    }

这是动画窗口

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-12 14:30:26

从第一次看,代码部分是好的。问题可能出在动画师那部分。如果在Z_Run状态中没有空闲动画(只有正在运行的动画),僵尸到达他无法停止运行的播放器(我不确定这是否是问题所在,您需要更具体地处理这个部分)。此外,为了使动画平滑,我建议当您的navAgent到达“接近”播放机时,它应该降低速度,然后在它实际到达时将速度再次降低到零,然后转向空闲动画(如果您使用基本的混合树作为状态,则应该能够完成Z_Run状态中的最后一部分)。看看“团结”中关于混合树木的文档。

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

https://stackoverflow.com/questions/60189859

复制
相关文章

相似问题

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