Ejemplo n.º 1
0
        /// <summary>
        /// MoveController 摇杆输入
        /// MobaMeSync 网络输入
        /// 两个综合考虑
        /// </summary>
        /// <returns></returns>
        public override IEnumerator RunLogic()
        {
            networkMove = GetAttr().GetComponent <ISyncInterface>();
            var physics = GetAttr().GetComponent <CreepMeleeAI>();

            while (!quit)
            {
                var curInfo   = networkMove.GetServerVelocity();
                var isNetMove = MobaUtil.IsServerMove(curInfo);
                if (isNetMove)
                {
                    if (isNetMove)//依赖服务器寻路
                    {
                        MoveByNet();
                    }
                    yield return(null);
                }
                else
                {
                    break;
                }
            }
            if (!quit)
            {
                aiCharacter.ChangeState(AIStateEnum.IDLE);
            }
        }
Ejemplo n.º 2
0
        /*
         * private IEnumerator MoveSmooth()
         * {
         *  var netPos = networkMove.GetServerPos();
         *  var curPos = GetAttr().transform.position;
         *  Log.AI("MoveSmooth:"+netPos+":"+curPos);
         *  var tarDir = netPos - curPos;
         *  tarDir.y = 0;
         *
         *  var speedCoff = MobaUtil.GetSpeedCoff(curPos, netPos);
         *  var oriSpeed = aiCharacter.GetAttr().GetSpeed() * speedCoff;
         *  var mdir = tarDir.normalized;
         *  physics.TurnTo(mdir);
         *  var sp = mdir * oriSpeed;
         *
         *  var passTime = 0.0f;
         *  var totalTime = tarDir.magnitude / oriSpeed;
         *  //不要玩家预测移动之后又回头 最终停下来的时候
         *  if (totalTime > 0.1f)
         *  {
         *      while (!quit && passTime < totalTime)
         *      {
         *          passTime += Time.deltaTime;
         *          var newPos = Vector3.Lerp(curPos, netPos, Mathf.Clamp01(passTime / totalTime));
         *          physics.MoveToIgnorePhysic(newPos);
         *          yield return null;
         *      }
         *  }else
         *  {
         *      yield return null;
         *  }
         *  //var newPos = GetAttr().transform.position + sp * Time.deltaTime;
         * }
         */

        /// <summary>
        /// 自己玩家正常速度移动
        /// </summary>
        private void MoveByNet()
        {
            var netPos = networkMove.GetServerPos();
            var curPos = GetAttr().transform.position;
            var tarDir = netPos - curPos;

            tarDir.y = 0;
            var deltaDist = tarDir.magnitude;


            var speedCoff = MobaUtil.GetSpeedCoff(curPos, netPos);
            var oriSpeed  = aiCharacter.GetAttr().GetSpeed() * speedCoff;

            /*
             * var sp = tarDir / Util.FrameSecTime;
             * var mag = sp.magnitude;
             * if(mag > oriSpeed*2)
             * {
             *  mag = oriSpeed*2;
             * }
             */

            Log.AI("MoveMe:" + curPos + ":" + netPos + ":" + networkMove.GetServerVelocity() + ":" + networkMove.GetCurInfoPos() + ":" + networkMove.GetCurInfoSpeed());

            /*
             * var dist = tarDir.magnitude;
             * var serverVel = networkMove.GetServerVelocity();
             * if (!MobaUtil.IsServerMove(serverVel) && dist < 1)
             * {
             *  return;
             * }
             */



            var mdir   = tarDir.normalized;
            var netDir = MobaUtil.GetNetTurnTo(vcontroller.inputVector, mdir, deltaDist, physics.transform.forward);

            physics.TurnTo(netDir);

            if (Mathf.Abs(deltaDist) < 0.1f)
            {
            }
            else
            {
                //sp = mdir * mag;
                //var speed2X = speed * 2;
                var sp     = mdir * oriSpeed;
                var newPos = GetAttr().transform.position + sp * Time.fixedDeltaTime;
                physics.MoveToIgnorePhysic(newPos);
            }
            //physics.MoveToIgnorePhysic(newPos);
        }
Ejemplo n.º 3
0
        public static bool IsServerMoveBySpeedOrPos(ISyncInterface sync)
        {
            var speed = sync.GetServerVelocity();

            if (IsServerMove(speed))
            {
                return(true);
            }

            var pos      = sync.GetServerPos();
            var posDelta = IsNetMove(pos, sync.transform.position);

            return(posDelta);
        }