/// <summary> /// Performs a walljump if the conditions are met /// </summary> protected virtual void Walljump() { if (!AbilityAuthorized || _condition.CurrentState != CharacterStates.CharacterConditions.Normal) { return; } // wall jump float wallJumpDirection; // if we're here the jump button has been pressed. If we were wallclinging, we walljump if (_movement.CurrentState == CharacterStates.MovementStates.WallClinging) { _movement.ChangeState(CharacterStates.MovementStates.WallJumping); // we decrease the number of jumps left if ((_characterJump != null) && ShouldReduceNumberOfJumpsLeft) { _characterJump.SetNumberOfJumpsLeft(_characterJump.NumberOfJumpsLeft - 1); } _characterJump.SetJumpFlags(); _condition.ChangeState(CharacterStates.CharacterConditions.Normal); _controller.GravityActive(true); _controller.SlowFall(0f); // If the character is colliding to the right with something (probably the wall) if (_character.IsFacingRight) { wallJumpDirection = -1f; } else { wallJumpDirection = 1f; } _characterHorizontalMovement?.SetAirControlDirection(wallJumpDirection); Vector2 walljumpVector = new Vector2( wallJumpDirection * WallJumpForce.x, Mathf.Sqrt(2f * WallJumpForce.y * Mathf.Abs(_controller.Parameters.Gravity)) ); if (ForceMode == ForceModes.AddForce) { _controller.AddForce(walljumpVector); } else { _controller.SetForce(walljumpVector); } PlayAbilityStartFeedbacks(); WallJumpHappenedThisFrame = true; OnWallJump?.Invoke(); return; } }
/// <summary> /// Performs a walljump if the conditions are met /// </summary> protected virtual void Walljump() { if (!AbilityPermitted || _condition.CurrentState != CharacterStates.CharacterConditions.Normal) { return; } // wall jump float wallJumpDirection; // if we're here the jump button has been pressed. If we were wallclinging, we walljump if (_movement.CurrentState == CharacterStates.MovementStates.WallClinging) { _movement.ChangeState(CharacterStates.MovementStates.WallJumping); // we decrease the number of jumps left if (_characterJump != null) { _characterJump.SetNumberOfJumpsLeft(_characterJump.NumberOfJumpsLeft - 1); _characterJump.SetJumpFlags(); // we start our sounds PlayAbilityStartSfx(); } _condition.ChangeState(CharacterStates.CharacterConditions.Normal); _controller.GravityActive(true); _controller.SlowFall(0f); // If the character is colliding to the right with something (probably the wall) if (_controller.State.IsCollidingRight) { wallJumpDirection = -1f; } else { wallJumpDirection = 1f; } Vector2 walljumpVector = new Vector2( wallJumpDirection * WallJumpForce.x, Mathf.Sqrt(2f * WallJumpForce.y * Mathf.Abs(_controller.Parameters.Gravity)) ); _controller.AddForce(walljumpVector); WallJumpHappenedThisFrame = true; return; } }