Exemplo n.º 1
0
        private void Move(Vector2 inputDir)
        {
            //Get the target move speed.
            Vector2 targetMoveSpeed = new Vector2(moveSpeed * inputDir.x, moveSpeed * inputDir.y);

            //Interpolate the move speed to get smooth movement.
            currentMoveSpeed.x = MathEx.Lerp(currentMoveSpeed.x, targetMoveSpeed.x, Time.FrameDelta / 0.04f);
            currentMoveSpeed.y = MathEx.Lerp(currentMoveSpeed.y, targetMoveSpeed.y, Time.FrameDelta / 0.04f);

            //Apply gravity.
            currentGravityAmount -= gravity * Time.FrameDelta;

            //Jumping.
            if (Input.IsButtonDown(ButtonCode.Space) && isGrounded)
            {
                currentGravityAmount = MovementUtilities.CalculateJumpVelocity(gravity, jumpHeight);
            }

            //Calculate the move velocity.
            Vector3 moveVelocity = SceneObject.Forward * currentMoveSpeed.y + SceneObject.Right * currentMoveSpeed.x + Vector3.YAxis * currentGravityAmount;

            //Move the player and catch the collision flag.
            CharacterCollisionFlag collisionInfo = controller.Move(moveVelocity * Time.FrameDelta);

            //Pass the collision flag to the collision handler method, and invoke it.
            ProcessCollisionInfo(collisionInfo);
        }