Esempio n. 1
0
 //以下为cal函数组,主要计算每个阶段的targetPos和WalkSpeed
 private void calGotoWallParam()
 {
     m_wallWalkTargetPos = m_wallWalkStartPos;
     m_wallWalkSpeed     = m_pFSM.creaturePropety.wallWalkSpeed;
     m_pFSM.FaceTo(m_wallWalkTargetPos);
 }
Esempio n. 2
0
    private void updateAutoMove()
    {
        if (!isAutoMoving || !m_pFSM.soliderController)
        {
            return;
        }

        //强制位移时不自动寻路
        if (m_pFSM.animatorCtrl.bDoingAttackMove || bForceMoving || bForceFlighting)
        {
            StopAutoMove();
            return;
        }

        if (m_pFSM.soliderController)
        {
            if (m_pFSM.inputMoveDirection.sqrMagnitude > 0.001f)
            {
                StopAutoMove();
                return;
            }

            if (!m_pFSM.soliderController.canMove())
            {
                StopAutoMove();
                return;
            }
        }

        if ((autoMoveTarget - m_pFSM.transform.position).sqrMagnitude < 0.25f) //到达目标点
        {
            StopAutoMove();
            return;
        }


        Vector3 deta = autoMovePathPoint[autoMovePathPointIndex] - m_pFSM.transform.position;

        deta.y = 0; //目前只考虑平面
        Vector3 detaDir  = deta.normalized;
        Vector3 faceDeta = m_pFSM.transform.position - lastTurnPoint;

        faceDeta.y = 0;//目前只考虑平面
        Vector3 faceDir = faceDeta.normalized;
        Vector3 step    = m_pFSM.transform.position - lastAutoMovePoint;

        step.y = 0;

        if (deta.sqrMagnitude < 0.09f || ((deta.sqrMagnitude < step.sqrMagnitude) && (Vector3.Dot(detaDir, faceDir) < 0))) //离下一个目标点很近或者已经超越目标点
        {
            //if (showLog)
            //{
            //    Trace.Log("index="+autoMovePathPointIndex);
            //    Trace.Log("autoMovePathPoint=" + autoMovePathPoint[autoMovePathPointIndex]);
            //    Trace.Log("position=" + transform.position);
            //    Trace.Log("deta=" + deta);
            //    Trace.Log("faceDeta=" + faceDeta);
            //    Trace.Log("detaDir=" + detaDir);
            //    Trace.Log("faceDir=" + faceDir);
            //    Trace.Log("deta.magnitude=" + deta.magnitude);
            //    Trace.Log("faceDeta.magnitude=" + faceDeta.magnitude);
            //    Trace.Log("Vector3.Dot(detaDir, faceDir)=" + Vector3.Dot(detaDir, faceDir));

            //}


            autoMovePathPointIndex++;

            lastTurnPoint = m_pFSM.transform.position;

            if (autoMovePathPointIndex >= autoMovePathPoint.Length) //走完所有路点
            {
                StopAutoMove();
                return;
            }
            deta    = autoMovePathPoint[autoMovePathPointIndex] - m_pFSM.transform.position;
            detaDir = deta.normalized;

            if (deta.sqrMagnitude < 0.25f) //太近了就不要转向了。因为在跑动中连续点寻路有时候会后退一个路点
            {
                autoMovePathPoint[0] = m_pFSM.transform.position;
            }

            //if (showLog)
            //{
            //    Trace.Log("Tick=" + GameLogicAPI.getTickCount() + " autoMove from " + transform.position + " to " + autoMovePathPoint[autoMovePathPointIndex]);
            //}
        }
        m_pFSM.autoMoveDirection = detaDir;
        //float angleDot = Vector3.Dot(autoMoveDirection, transform.forward);
        //if (angleDot < 0.99f)
        //{

        if (m_pFSM.soliderController.canRotate() && !m_pFSM.soliderController.isAttackMode())
        {
            m_pFSM.FaceTo(m_pFSM.transform.position + m_pFSM.autoMoveDirection * 10.0f);
        }

        //}

        lastAutoMovePoint = m_pFSM.transform.position;
    }