Example #1
0
    private void SetPosition(HisPosInfo hisPosInfo, float rateT)
    {
        Vector3 showPos = hisPosInfo.ShowPos;

        if (navAgent && useNavAgent)                    //使用NavAgent修改位置
        {
            navAgent.SetDestination(hisPosInfo, rateT); //新的设置位置的有效代码
        }
        else
        {
            //原来的有效代码
            float disT = Vector3.Distance(showPos, transform.position);
            if (disT < maxMoveLength && enableMoveByController)//如果当前位置与目标位置超过三维里的一个单位(不考虑y轴方向),就可以进行穿墙移动,小于一个单位会被阻挡
            {
                if (personmove != null)
                {
                    personmove.SetPosition_History(showPos);//CharactorController控制走路,会被墙等物体挡住。
                }
            }
            else
            {
                transform.position = showPos;//根据历史轨迹走路
            }
        }

        if (navAgentFollow)//跟谁人员,不用管原来的代码,设置跟随人员的位置就行
        {
            navAgentFollow.SetDestination(hisPosInfo, rateT);
        }
    }