示例#1
0
        public override void Act(GameObject npc, GameObject player)
        {
            Debug.LogFormat("ChasingPlayerState  追踪敌人------------ ");
            if (targetPlayer == null)
            {
                Debug.LogErrorFormat("ChasingPlayerState -> Act() -> targetPlayer == null ");
                return;
            }
            if (npc == null)
            {
                Debug.LogErrorFormat("npc == null ");
                return;
            }
            if (mINPC == null)
            {
                mINPC = npc.GetComponent <INPC>();
            }

            Vector3 moveDir = targetPlayer.transform.position - npc.transform.position;

            moveDir.y -= 9.8f;

            Quaternion quaternion = Quaternion.Slerp(npc.transform.rotation, Quaternion.LookRotation(moveDir), 5 * Time.deltaTime);

            npc.transform.eulerAngles = new Vector3(0, quaternion.eulerAngles.y, 0);

            //mCharacterController.Move(moveDir.normalized * Time.deltaTime * 2);
            mINPC.Move(moveDir.normalized * Time.deltaTime * 2);
        }
 public override void Act(GameObject npc, GameObject player)
 {
     if (targetPlayer == null)
     {
         Debug.LogErrorFormat("AttackPlayerState -> Act() -> targetPlayer == null ");
         return;
     }
     if (npc == null)
     {
         Debug.LogErrorFormat("AttackPlayerState -> Act() -> npc == null ");
         return;
     }
     if (mINPC == null)
     {
         mINPC = npc.GetComponent <INPC>();
     }
     mINPC.Attack(targetPlayer);
 }
示例#3
0
        public override void Act(GameObject npc, GameObject player)
        {
            Debug.LogFormat("FollowPathState  自动寻路------------ ");
            if (npc == null)
            {
                Debug.LogErrorFormat("npc == null ");
                return;
            }
            if (mINPC == null)
            {
                mINPC = npc.GetComponent <INPC>();
            }

            Vector3 moveDir = wayPoints[currentWayPoint].position - npc.transform.position;
            Vector3 dir     = moveDir.normalized;

            dir.y -= 9.8f;

            if (moveDir.magnitude < 1.5f)
            {
                currentWayPoint++;
                if (currentWayPoint >= wayPoints.Length)
                {
                    currentWayPoint = 0;
                }
            }
            else
            {
                Quaternion quaternion = Quaternion.Slerp(npc.transform.rotation, Quaternion.LookRotation(moveDir), 5 * Time.deltaTime);
                npc.transform.eulerAngles = new Vector3(0, quaternion.eulerAngles.y, 0);
            }

            //mCharacterController.Move(moveDir.normalized * Time.deltaTime * 5);
            //mCharacterController.Move(dir * Time.deltaTime * 2);
            mINPC.Move(dir * Time.deltaTime * 2);
        }