Пример #1
0
    // public float _dodgeYVel = 8;
    private void Dodge()
    {
        if (_dodged || !IsPlayerOnGround)
        {
            return;
        }
        _landed            = false;
        _dodgeTimeProgress = 0;
        PlayerStates.Set(PlayerStates.AnimationParameter.DodgingInAir);
        PlayerStates.UnSet(PlayerStates.AnimationParameter.Running);
        PlayerStates.UnSet(PlayerStates.AnimationParameter.Idling);
        PlayerStates.Set(PlayerStates.AnimationParameter.Dodge);

        _dodged = true;
        if (_isRunKeyPressed) //a key is pressed
        {
            _playerFacingDirection = _playerFacingDirection == Direction.Left
                ? Direction.Right : Direction.Left; //flip the direction before dodge(and then dodge in the opposite of the flipped direction)
        }
        int horizontalVelocityDirection = 1;

        if (_playerFacingDirection == Direction.Right)
        {
            horizontalVelocityDirection = -1; //player should dodge left
        }
        float timeOfFlight = _dodgeDistance / _dodgeSpeed;
        float dodgeYVel    = -Physics.gravity.y * timeOfFlight;

        _rigidBody.velocity = new Vector2(_dodgeSpeed * horizontalVelocityDirection, dodgeYVel);//.Set(dodgeHVel, _dodgeYVel);
    }
 public static void OnFallDodge()
 {
     PlayerStates.Set(PlayerStates.AnimationParameter.Falling);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.Running);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.Idling);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.DodgingInAir);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.DodgeLanding);
 }
Пример #3
0
 private void Jump()
 {
     if (IsPlayerOnGround && _landed)
     {
         PlayerStates.UnSet(PlayerStates.AnimationParameter.Running);
         PlayerStates.Set(PlayerStates.AnimationParameter.Jump);
         PlayerStates.Set(PlayerStates.AnimationParameter.Jumping);
         Vector2 jumpVelocityVector = new Vector2(0, PhysicsHelper.GetVelocityToReachHeight(_jumpHeight));
         _rigidBody.velocity = jumpVelocityVector;
     }
 }
Пример #4
0
 private void SetCrouch(bool crouch)
 {
     if (!IsPlayerOnGround)
     {
         _isCrouching = false; //can't crouch when not on ground
         PlayerStates.UnSet(PlayerStates.AnimationParameter.Crouching);
         return;
     }
     if (crouch)
     {
         _isCrouching = true;
         PlayerStates.Set(PlayerStates.AnimationParameter.Crouching);
     }
     else
     {
         _isCrouching = false;
         PlayerStates.UnSet(PlayerStates.AnimationParameter.Crouching);
     }
 }
Пример #5
0
    private void OnLanding()
    {
        _landed = true;
        if (_dodged)
        {
            PlayerStates.UnSet(PlayerStates.AnimationParameter.DodgingInAir);
            PlayerStates.Set(PlayerStates.AnimationParameter.DodgeLanding);
            //_bDampDodge = true;
            SetVelocityForDampingForDodge();
        }

        /*  else if (!_isRunKeyPressed)
         * {
         *    SetVelocityForDamping();
         * }*/
        _falling = false;

        PlayerStates.UnSet(PlayerStates.AnimationParameter.Falling);
        PlayerStates.ResetTrigger(PlayerStates.AnimationParameter.Jump);
        PlayerStates.UnSet(PlayerStates.AnimationParameter.Jumping);
    }
Пример #6
0
    private void ProcessKeyPress()
    {
        _prevAxisValueX = _axisValueX;
        _prevAxisValueY = _axisValueY;
        _axisValueX     = Input.GetAxisRaw("Horizontal"); //don't need smoothing
        _axisValueY     = Input.GetAxisRaw("Vertical");
        if (!_dodged)
        {
            if (_axisValueX < 0) //leftwards movement
            {
                _playerFacingDirection = Direction.Left;
                _keyDirection          = Direction.Left;
            }
            else if (_axisValueX > 0)
            {
                _playerFacingDirection = Direction.Right;
                _keyDirection          = Direction.Right;
            }
            if (_axisValueX != 0 && _axisValueY >= 0)
            {
                _isRunKeyPressed = true;
                if (IsPlayerOnGround && !_isCrouching)
                {
                    PlayerAnimationHandler.OnRun();
                }
                PlayerAnimationHandler.OnUnIdle();

                // PlayerStates.UnSet(PlayerStates.AnimationParameter.Stop);
            }
            else
            {
                if (_isRunKeyPressed && !_dodged)  //movement key(s)was pressed till now
                {
                    PlayerAnimationHandler.OnNoMoveKeysPressed();

                    if (PhysicsHelper.CollidingWithSomethingOnEitherSide(_boxCollider, _standableObjectLayerMask))
                    {
                        PlayerStates.Set(PlayerStates.AnimationParameter.DirectIdle);
                    }
                    else
                    {
                        if (!_isCrouching)
                        {
                            PlayerAnimationHandler.OnStop();
                        }
                        SetVelocityForDamping();
                    }
                }
                _isRunKeyPressed = false;
                if (IsPlayerOnGround)
                {
                    PlayerAnimationHandler.OnIdling();            //if on ground and no key is pressed, should be idling
                }
            }


            if (_axisValueY > 0 && IsKeyShiftVertical) //don't jump if jump was held
            {
                Jump();
            }
        }
        if (Input.GetKeyDown(KeyCode.J) && !_dodged)
        {
            Dodge();
        }
        if (_axisValueY < 0)
        {
            SetCrouch(true);
        }
        else
        {
            SetCrouch(false);
        }



        if (_isRunKeyPressed && !_dodged && !_isCrouching)
        {
            Vector2 runVector = new Vector3(_runSpeed * _axisValueX, _rigidBody.velocity.y);
            //transform.position += _runVector;
            _rigidBody.velocity = runVector;
        }
    }
 public static void OnIdling()
 {
     PlayerStates.Set(PlayerStates.AnimationParameter.Idling);
 }
 public static void OnStop()
 {
     PlayerStates.Set(PlayerStates.AnimationParameter.Stop);
 }
 public static void OnRun()
 {
     PlayerStates.Set(PlayerStates.AnimationParameter.Running);
 }
 public static void OnDodgeEndLandFall()
 {
     PlayerStates.UnSet(PlayerStates.AnimationParameter.DodgingInAir);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.DodgeLanding);
     PlayerStates.Set(PlayerStates.AnimationParameter.Falling);
 }
 public static void OnFall()
 {
     PlayerStates.Set(PlayerStates.AnimationParameter.Falling);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.Running);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.Idling);
 }