/// <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;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Triggered when something collides with the override zone
        /// </summary>
        /// <param name="collider">Something colliding with the override zone.</param>
        protected virtual void OnTriggerEnter2D(Collider2D collider)
        {
            // we check that the object colliding with the override zone is actually a characterJump
            CharacterJump characterJump = collider.GetComponent <CharacterJump>();

            if (characterJump == null)
            {
                return;
            }

            _previousJumpHeight         = characterJump.JumpHeight;
            _previousJumpMinimumAirTime = characterJump.JumpMinimumAirTime;
            _previousNumberOfJumps      = characterJump.NumberOfJumps;
            _previousJumpRestrictions   = characterJump.JumpRestrictions;
            _previousNumberOfJumpsLeft  = characterJump.NumberOfJumpsLeft;

            characterJump.JumpHeight         = JumpHeight;
            characterJump.JumpMinimumAirTime = JumpMinimumAirTime;
            characterJump.NumberOfJumps      = NumberOfJumps;
            characterJump.JumpRestrictions   = JumpRestrictions;
            if (ResetNumberOfJumpsLeft)
            {
                characterJump.SetNumberOfJumpsLeft(NumberOfJumps);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Restore the initial values for the colliding CharacterJump
        /// </summary>
        protected virtual void Restore()
        {
            if (_characterJump == null)
            {
                return;
            }

            _characterJump.JumpHeight         = _previousJumpHeight;
            _characterJump.JumpMinimumAirTime = _previousJumpMinimumAirTime;
            _characterJump.NumberOfJumps      = _previousNumberOfJumps;
            _characterJump.JumpRestrictions   = _previousJumpRestrictions;
            if (ResetNumberOfJumpsLeft)
            {
                _characterJump.SetNumberOfJumpsLeft(_characterJump.NumberOfJumps);
            }
            else
            {
                _characterJump.SetNumberOfJumpsLeft(_previousNumberOfJumpsLeft);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Triggered when something exits the water
        /// </summary>
        /// <param name="collider">Something colliding with the water.</param>
        protected virtual void OnTriggerExit2D(Collider2D collider)
        {
            // we check that the object colliding with the water is actually a characterJump
            CharacterJump characterJump = collider.GetComponent <CharacterJump>();

            if (characterJump == null)
            {
                return;
            }

            characterJump.JumpHeight         = _previousJumpHeight;
            characterJump.JumpMinimumAirTime = _previousJumpMinimumAirTime;
            characterJump.NumberOfJumps      = _previousNumberOfJumps;
            characterJump.JumpRestrictions   = _previousJumpRestrictions;
            if (ResetNumberOfJumpsLeft)
            {
                characterJump.SetNumberOfJumpsLeft(characterJump.NumberOfJumps);
            }
            else
            {
                characterJump.SetNumberOfJumpsLeft(_previousNumberOfJumpsLeft);
            }
        }
        /// <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;
            }
        }