Exemplo n.º 1
0
    void CalculateMovement(ref GameTime gameTime, ref CharacterPredictedData predicted, ref UserCommand command, ref Vector3 deltaPos)
    {
        var velocity = predicted.velocity;

        switch (predicted.locoState)
        {
        case CharacterPredictedData.LocoState.Jump:

            // In jump we overwrite velocity y component with linear movement up
            var speed = new Vector3(velocity.x, 0, velocity.z).magnitude;
            if (speed > Game.config.playerSpeed)
            {
                velocity *= Game.config.playerSpeed / speed;
            }
            velocity   = CalculateGroundVelocity(velocity, ref command, Game.config.playerSpeed, Game.config.playerAirFriction, Game.config.playerAiracceleration, gameTime.tickDuration);
            velocity.y = (predicted.boosting == 1) ? Game.config.playerInAirBoostingSpeed : Game.config.jumpAscentHeight / Game.config.jumpAscentDuration;
            deltaPos  += velocity * gameTime.tickDuration;

            return;

        case CharacterPredictedData.LocoState.InAir:

            var gravity = Game.config.playerGravity;
            velocity += Vector3.down * gravity * gameTime.tickDuration;
            velocity  = CalculateGroundVelocity(velocity, ref command, Game.config.playerSpeed, Game.config.playerAirFriction, Game.config.playerAiracceleration, gameTime.tickDuration);

            if (predicted.boosting == 1)
            {
                velocity.y = Game.config.playerInAirBoostingSpeed;
            }
            else
            {
                if (velocity.y < -Game.config.maxFallVelocity)
                {
                    velocity.y = -Game.config.maxFallVelocity;
                }
            }

            deltaPos = velocity * gameTime.tickDuration;

            return;
        }

        var playerSpeed = predicted.boosting == 1 ? Game.config.playerGroundBoostingSpeed : Game.config.playerSpeed;

        velocity = CalculateGroundVelocity(velocity, ref command, playerSpeed, Game.config.playerFriction, Game.config.playerAcceleration, gameTime.tickDuration);

        // Simple follow ground code so character sticks to ground when running down hill
        velocity.y = -400.0f * gameTime.tickDuration;

        deltaPos = velocity * gameTime.tickDuration;
    }
Exemplo n.º 2
0
    void CalculateMovement(ref GameTime gameTime, ref CharacterPredictedData predicted, ref UserCommand command, ref Vector3 deltaPos)
    {
        var velocity = predicted.velocity;

        switch (predicted.locoState)
        {
        case CharacterPredictedData.LocoState.Jump:
        case CharacterPredictedData.LocoState.DoubleJump:

            // In jump we overwrite velocity y component with linear movement up
            velocity   = CalculateGroundVelocity(velocity, ref command, Game.config.playerSpeed, Game.config.playerAirFriction, Game.config.playerAiracceleration, gameTime.tickDuration);
            velocity.y = Game.config.jumpAscentHeight / Game.config.jumpAscentDuration;
            deltaPos  += velocity * gameTime.tickDuration;

            return;

        case CharacterPredictedData.LocoState.InAir:

            var gravity = Game.config.playerGravity;
            velocity += Vector3.down * gravity * gameTime.tickDuration;
            velocity  = CalculateGroundVelocity(velocity, ref command, Game.config.playerSpeed, Game.config.playerAirFriction, Game.config.playerAiracceleration, gameTime.tickDuration);

            if (velocity.y < -Game.config.maxFallVelocity)
            {
                velocity.y = -Game.config.maxFallVelocity;
            }

            // Cheat movement
            if (command.buttons.IsSet(UserCommand.Button.Boost) && (Game.GetGameLoop <PreviewGameLoop>() != null))
            {
                velocity.y += 25.0f * gameTime.tickDuration;
                velocity.y  = Mathf.Clamp(velocity.y, -2.0f, 10.0f);
            }

            deltaPos = velocity * gameTime.tickDuration;

            return;
        }

        var playerSpeed = predicted.sprinting == 1 ? Game.config.playerSprintSpeed : Game.config.playerSpeed;

        velocity = CalculateGroundVelocity(velocity, ref command, playerSpeed, Game.config.playerFriction, Game.config.playerAcceleration, gameTime.tickDuration);
//        Debug.DrawLine(predictedState.State.position, predictedState.State.position + velocity, Color.yellow,1 );

        // Simple follow ground code so character sticks to ground when running down hill
        velocity.y = -400.0f * gameTime.tickDuration;

//        Debug.DrawLine(predictedState.State.position, predictedState.State.position + velocity, Color.green, 1 );

        deltaPos = velocity * gameTime.tickDuration;
    }