예제 #1
0
    private void MoveCharacterBasedOnInput()
    {
        var moveY = _inputProvider.ProvideMoveInputY();
        var moveX = _inputProvider.ProvideMoveInputX();

        var forwardsMovement = transform.forward * moveY;
        var sidewaysMovement = transform.right * moveX;

        var unifiedMovement          = (forwardsMovement + sidewaysMovement);
        var clampedMovementMagnitude = Mathf.Clamp01(unifiedMovement.magnitude) * GetMovementSpeed();

        /*
         *  If we don't multiply by the clamped movement magnitude, we will lose
         *  the "smooth"/analog input, and will get janky movement.
         *
         *  We also need to normalize the movement, otherwise our player will move
         *  faster while going diagonally because of the addition of vectors.
         */
        var normalizedMovement = unifiedMovement.normalized * clampedMovementMagnitude;

        _characterController.SimpleMove(normalizedMovement);
    }