Ejemplo n.º 1
0
        public override void Action(BaseFSM basefsm)
        {
            basefsm.PlayAnimation(basefsm.animParams.Walk);
            basefsm.MoveToTarget(basefsm.wayPoints[currentWayPoint].position, basefsm.walkSpeed, basefsm.patrolArrivalDistance);
            //1.是否到达当前路点
            if (Vector3.Distance(basefsm.transform.position, basefsm.wayPoints[currentWayPoint].position) < basefsm.patrolArrivalDistance)
            {
                //2.是否是最后一个路点
                if (currentWayPoint == basefsm.wayPoints.Length - 1)
                {
                    //根据巡逻的方式决定结束或开始
                    switch (basefsm.patrolMode)
                    {
                    case PatrolMode.Once:
                        basefsm.isPatrolComplete = true;
                        return;

                    case PatrolMode.PingPong:
                        break;

                    case PatrolMode.Loop:
                        currentWayPoint = 0;
                        break;
                    }
                }
                currentWayPoint += 1;
            }
        }
Ejemplo n.º 2
0
 public override void Action(BaseFSM fsm)
 {
     //判断是否到达路点
     if (Vector3.Distance(fsm.transform.position,
                          fsm.PatrolWayPoints[currentWayPointIndex].position) < arrivalDistance)
     {
         if (currentWayPointIndex == fsm.PatrolWayPoints.Length - 1)
         {
             if (fsm.patrolMode == PatrolMode.Once)//单程
             {
                 patrolComplete       = true;
                 currentWayPointIndex = 0;
                 return;
             }
             //结束巡逻
             else if (fsm.patrolMode == PatrolMode.PingPong)
             {
                 Array.Reverse(fsm.PatrolWayPoints);
             }
         }
         //到 : 换下一个路点
         currentWayPointIndex += 1;
         currentWayPointIndex  = currentWayPointIndex % fsm.PatrolWayPoints.Length;
     }
     currentWayPoint = fsm.PatrolWayPoints[currentWayPointIndex];
     fsm.MoveToTarget(currentWayPoint.position, fsm.walkSpeed, fsm.RotationSpeed, arrivalDistance);
     //播动画
     fsm.PlayAnimation(fsm.animParams.Walk);
 }
Ejemplo n.º 3
0
 public override void Action(BaseFSM fsm)
 {
     //播放跑动画
     if (fsm.targetPlayer != null && fsm.targetPlayer.gameObject != null)
     {
         fsm.PlayAnimation(fsm.animParams.Run);
         fsm.MoveToTarget(fsm.targetPlayer.position, fsm.MoveSpeed, fsm.RotationSpeed);
     }
 }
Ejemplo n.º 4
0
 public override void Action(BaseFSM fsm)
 {
     if (fsm.targetObject != null)
     {
         fsm.MoveToTarget(
             fsm.targetObject.transform.position,
             fsm.moveSpeed,
             fsm.chStatus.chBase.attackDistance);
         // 播放响应的动画
         fsm.PlayAnimation(fsm.animParams.Run);
     }
 }
Ejemplo n.º 5
0
 public override void Action(BaseFSM fsm)
 {
     if (animationIsRun == false)
     {
         fsm.PlayeAnimation(fsm.animNames.Run);
         animationIsRun = true;
     }
     //播放跑动画
     if (fsm.targetPlayer != null && fsm.targetPlayer.gameObject != null)
     {
         fsm.MoveToTarget(fsm.targetPlayer.position, fsm.MoveSpeed, fsm.RotationSpeed);
     }
 }
Ejemplo n.º 6
0
 //往返
 private void PingPongPatrolling(BaseFSM fsm)
 {
     //A   B   C   ……  A   B   C
     if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) < 0.5f)
     {
         //索引反转:0    1    2   ……    1   0
         //             A    B   C   …… C   B   A
         //数组反转:0   1   2  ……  0   1   2
         Array.Reverse(fsm.wayPoints);
         index++;
         index = (index + 1) % fsm.wayPoints.Length;
     }
     //移动
     fsm.MoveToTarget(fsm.wayPoints[index].position, fsm.walkSpeed, 0);
 }
Ejemplo n.º 7
0
        public override void Action(BaseFSM basefsm)
        {
            //1.条件需要有追逐的目标
            if (basefsm.targetObj != null)
            {
                //2.播放追逐动画
                basefsm.PlayAnimation(basefsm.animParams.Run);
                basefsm.MoveToTarget(basefsm.targetObj.position, basefsm.moveSpeed, basefsm.chState.attackDistance);

                //3.主要控制追的速度,靠近的距离==攻击距离
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 8
0
 //单次
 private void OncePatrolling(BaseFSM fsm)
 {
     //A   B   C
     if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) < 0.5f)
     {
         if (index == fsm.wayPoints.Length - 1)
         {
             //巡逻完成
             fsm.isPatrolComplete = true;
             return;
         }
         index++;
     }
     //移动
     fsm.MoveToTarget(fsm.wayPoints[index].position, fsm.walkSpeed, 0);
 }
Ejemplo n.º 9
0
        //循环
        private void LoopPatrolling(BaseFSM fsm)
        {
            //A   B   C   ……  A   B   C

            if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) < 0.5f)
            {
                //if (index == fsm.wayPoints.Length - 1)
                //    index = -1;
                //index++;
                //0   +   1     %   3
                //1   +   1           3
                //2   +   1           3
                index = (index + 1) % fsm.wayPoints.Length;
            }
            //移动
            fsm.MoveToTarget(fsm.wayPoints[index].position, fsm.walkSpeed, 0);
        }
Ejemplo n.º 10
0
 public override void Action(BaseFSM fsm)
 {
     fsm.MoveToTarget();
 }
Ejemplo n.º 11
0
        public override void Action(BaseFSM fsm)
        {
            base.Action(fsm);

            fsm.MoveToTarget(fsm.targetTF.position, fsm.runSpeed, fsm.chStatus.attackDistance);
        }