Пример #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);
    }
 public static void OnNoMoveKeysPressed()
 {
     PlayerStates.UnSet(PlayerStates.AnimationParameter.Running);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.Idling);
 }
 public static void OnUnIdle()
 {
     PlayerStates.UnSet(PlayerStates.AnimationParameter.Idling);
 }
 public static void OnDodgeEndDamp()
 {
     PlayerStates.UnSet(PlayerStates.AnimationParameter.DodgeLanding);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.DodgingInAir);
 }
 public static void OnFall()
 {
     PlayerStates.Set(PlayerStates.AnimationParameter.Falling);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.Running);
     PlayerStates.UnSet(PlayerStates.AnimationParameter.Idling);
 }