Пример #1
0
        public static void Move(Contexts contexts, PlayerEntity player, float deltaTime)
        {
            var controller = player.characterContoller.Value;

            SyncTransformFromComponent(player);

            // 分离角色
            ResolveOverlapWithPlayer(contexts, player);

            // 旋转角色
            RotateCharacter(player, deltaTime);

            var finalVec = SpeedCalculator.CalcSpeed(player, deltaTime);

            var dist = finalVec * deltaTime;

            SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.ClientMove);
            // 移动角色
            PlayerMoveUtility.Move(contexts, player, controller, dist, deltaTime);
            SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.ClientMove);

            SetIsCollider(player);
            ChangeVelocityYAfterCollision(player);
            CalcGroundSteep(player);
            CalcMoveVel(player, deltaTime);
            UpdatePlayerComponent(player);
        }
Пример #2
0
        public static void Move(Contexts contexts, PlayerEntity player, float deltaTime)
        {
            var state           = player.stateInterface.State;
            var postureInConfig = state.GetNextPostureState();

            var controller = player.characterContoller.Value;

            controller.SetCurrentControllerType(postureInConfig);

            var diveXAngle = CalcDiveXAngle(state.VerticalValue, state.HorizontalValue, state.UpDownValue);

            controller.SetCharacterPosition(player.position.Value);
            //_logger.InfoFormat("my epxected rot:x:{0},y:{1}, new:{2}", diveXAngle, YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw),YawPitchUtility.Normalize(Quaternion.Euler(diveXAngle,YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw), 0 )).ToStringExt() );
            controller.SetCharacterRotation(new Vector3(diveXAngle, YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw), 0));

            var velocity = player.stateInterface.State.GetSpeed(Vector3.zero, deltaTime);

            velocity = player.orientation.RotationView * velocity.ToVector4();
            var velocityOffset = player.stateInterface.State.GetSpeedOffset();

            var dist = (velocity + velocityOffset) * deltaTime;

            PlayerMoveUtility.Move(contexts, player, player.characterContoller.Value, dist, deltaTime);

            //_logger.InfoFormat("dive move dist:{0}, prev pos:{1}, after pos:{2}", dist.ToStringExt(), player.position.Value.ToStringExt(), controller.transform.position.ToStringExt());
            player.playerMove.Velocity = velocity;
            player.position.Value      = controller.transform.position;
        }
Пример #3
0
        private void MoveOnGround(PlayerEntity player, float deltaTime, bool moveInWater)
        {
            var state           = player.stateInterface.State;
            var postureInConfig = state.GetNextPostureState();
            var controller      = player.characterContoller.Value;

            //旋转包围盒
            RotBox(player, deltaTime, postureInConfig, controller);

            var playerRoot    = player.RootGo();
            var syncTransform = playerRoot.transform;
            var lastVel       = Quaternion.Inverse(player.orientation.RotationYaw) * player.playerMove.Velocity.ToVector4();;

            Vector4 velocity             = lastVel.ToVector4();
            Vector4 velocityOffset       = Vector3.zero.ToVector4();
            float   latestCollisionSlope = 0f;

            CalculateVelocity(ref velocity, ref velocityOffset, ref latestCollisionSlope, deltaTime, player,
                              moveInWater, controller, lastVel);

            //坡度计算
            if (state.GetCurrentPostureState() == PostureInConfig.Jump && ((int)controller.collisionFlags & (int)UnityEngine.CollisionFlags.Sides) != 0)
            {
                JumpSpeedProject(ref velocity, controller);
            }
            //_logger.InfoFormat("curVel:{0},VelOffset:{1}", velocity.ToStringExt(), velocityOffset.ToStringExt());

            var scaledVel = (velocity);

            scaledVel.Scale(new Vector4(player.playerMove.MoveSpeedRatio, 1, player.playerMove.MoveSpeedRatio, 1));
            var dist = (scaledVel + velocityOffset) * deltaTime;

            PlayerMoveUtility.Move(_contexts, player, controller, dist, deltaTime);
            //_logger.InfoFormat("dist:{0}, velocity:{4},velocityOffset:{5} ,flag:{6}, nextCurState:{1}, controllerType:{2}, currentState:{3}", dist.ToStringExt(), postureInConfig, controller.GetCurrentControllerType(),state.GetCurrentPostureState(),velocity, velocityOffset, controller.collisionFlags);

            //落地或碰到天花板,速度降为0
            HandleCollision(ref velocity, player, controller, latestCollisionSlope);
            //_logger.InfoFormat("v.y:{0}, isGround:{1},latestCollisionSlope:{2}", player.playerMove.Velocity.y, player.playerMove.IsGround, latestCollisionSlope);
            CalcuSlope(player, syncTransform);

            player.stateInterface.State.SetMoveInWater(moveInWater);
            player.playerMove.Velocity = velocity;
            player.position.Value      = syncTransform.position;

            player.orientation.ModelPitch = YawPitchUtility.Normalize(syncTransform.rotation.eulerAngles.x);
            player.orientation.ModelYaw   = YawPitchUtility.Normalize(syncTransform.rotation.eulerAngles.y);
        }
Пример #4
0
        public static void Move(Contexts contexts, PlayerEntity player, float deltaTime)
        {
            var state = player.stateInterface.State;

            var postureInConfig = state.GetNextPostureState();

            var controller = player.characterContoller.Value;

            controller.SetCurrentControllerType(postureInConfig);

            controller.SetCharacterPosition(player.position.Value);

            var diveXAngle = CalcSwimXAngle(state.VerticalValue, state.HorizontalValue, state.UpDownValue);

            controller.SetCharacterRotation(new Vector3(diveXAngle, YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw), 0));

            var lastVel = Quaternion.Inverse(player.orientation.RotationYaw) * player.playerMove.Velocity.ToVector4();

            var velocity = player.stateInterface.State.GetSpeed(lastVel, deltaTime);

            velocity = player.orientation.RotationYaw * velocity.ToVector4();

            var velocityOffset = player.stateInterface.State.GetSpeedOffset();

            var dist = (velocity + velocityOffset) * deltaTime;

            if (DiveTest(player, velocityOffset, dist))
            {
                player.stateInterface.State.Dive();
                DiveHandler.Move(contexts, player, deltaTime);
                player.moveUpdate.BeginDive = true;
            }

            else
            {
                PlayerMoveUtility.Move(contexts, player, player.characterContoller.Value, dist, deltaTime);
                player.playerMove.Velocity = velocity;
                player.position.Value      = controller.transform.position;
            }
        }
Пример #5
0
        private void SwimMove(PlayerEntity player, float deltaTime, IUserCmd cmd)
        {
            var state           = player.stateInterface.State;
            var postureInConfig = state.GetNextPostureState();

            var controller = player.characterContoller.Value;

            controller.SetCurrentControllerType(postureInConfig);

            controller.SetCharacterPosition(player.position.Value);

            var diveXAngle = CalcSwimXAngle(state.VerticalValue, state.HorizontalValue, state.UpDownValue);

            controller.SetCharacterRotation(new Vector3(diveXAngle, YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw), 0));

            var lastVel  = Quaternion.Inverse(player.orientation.RotationYaw) * player.playerMove.Velocity.ToVector4();
            var velocity = player.stateInterface.State.GetSpeed(lastVel, deltaTime);

            velocity = player.orientation.RotationYaw * velocity.ToVector4();
            var velocityOffset = player.stateInterface.State.GetSpeedOffset();
            var dist           = (velocity + velocityOffset) * deltaTime;

            if (velocityOffset.magnitude > 0 || (player.stateInterface.State.IsForth && dist.sqrMagnitude > 0 && player.orientation.Pitch >= (SingletonManager.Get <CameraConfigManager>().GetConfigByType(ECameraConfigType.ThirdPerson).PitchLimit.Max - 1)))
            {
                player.stateInterface.State.Dive();
                DiveMove(player, deltaTime, cmd);
                player.moveUpdate.BeginDive = true;
            }
            else
            {
                PlayerMoveUtility.Move(_contexts, player, player.characterContoller.Value, dist, deltaTime);

                player.playerMove.Velocity = velocity;
                player.position.Value      = controller.transform.position;
            }
        }