Example #1
0
    /// <summary>
    /// Causes the character to start jumping.
    /// </summary>
    public void JumpStart()
    {
        // if the Jump action is enabled in the permissions, we continue, if not we do nothing. If the player is dead, we do nothing.
        if (!Permissions.JumpEnabled || !JumpAuthorized || BehaviorState.IsDead)
        {
            return;
        }

        // we check if the character can jump without conflicting with another action
        if (_controller.State.IsGrounded ||
            BehaviorState.LadderClimbing ||
            BehaviorState.NumberOfJumpsLeft > 0)
        {
            BehaviorState.CanJump = true;
        }
        else
        {
            BehaviorState.CanJump = false;
        }

        // if the player can't jump, we do nothing.
        if ((!BehaviorState.CanJump) && !(BehaviorParameters.JumpRestrictions == CharacterBehaviorParameters.JumpBehavior.CanJumpAnywhereAnyNumberOfTimes))
        {
            return;
        }

        // if the character is standing on a one way platform (layermask n°11) and is also pressing the down button,
        if (_verticalMove < 0 && _controller.State.IsGrounded)
        {
            if (_controller.StandingOn.layer == 11)
            {
                // we make it fall down below the platform by moving it just below the platform
                _controller.transform.position = new Vector2(transform.position.x, transform.position.y - 0.1f);
                // we turn the boxcollider off for a few milliseconds, so the character doesn't get stuck mid platform
                StartCoroutine(_controller.DisableCollisions(0.3f));
                return;
            }
        }

        // we decrease the number of jumps left
        BehaviorState.NumberOfJumpsLeft = BehaviorState.NumberOfJumpsLeft - 1;

        BehaviorState.LadderClimbing = false;
        BehaviorState.CanMoveFreely  = true;
        GravityActive(true);

        _jumpButtonPressTime = Time.time;
        _jumpButtonPressed   = true;
        _jumpButtonReleased  = false;

        _controller.SetVerticalForce(Mathf.Sqrt(2f * BehaviorParameters.JumpHeight * Mathf.Abs(_controller.Parameters.Gravity)));

        if (PlayerJumpSfx != null)
        {
            PlaySound(PlayerJumpSfx, transform.position);
        }
    }
Example #2
0
    public void RpcJetpackStart()
    {
        if (_tank != null && _tank.PushR == true)
        {
            return;
        }
        if (_stealth != null && _stealth.existTime < 5f && _stealth.existTime > 0f)
        {
            return;
        }

        if ((!_characterBehavior.Permissions.JetpackEnabled) || (!_characterBehavior.BehaviorState.CanJetpack) || (_characterBehavior.BehaviorState.IsDead))
        {
            return;
        }

        if (!_characterBehavior.BehaviorState.CanMoveFreely)
        {
            return;
        }

        if ((!JetpackUnlimited) && (_characterBehavior.BehaviorState.JetpackFuelDurationLeft <= 0f))
        {
            CmdJetpackStop();
            _characterBehavior.BehaviorState.CanJetpack = false;
            return;
        }


        _controller.SetVerticalForce(JetpackForce);
        _characterBehavior.BehaviorState.Jetpacking = true;
        _characterBehavior.BehaviorState.CanMelee   = false;
        _characterBehavior.BehaviorState.CanJump    = false;
        Jetpack.enableEmission = true;
        if (!JetpackUnlimited)
        {
            StartCoroutine(JetpackFuelBurn());
        }
    }