Exemplo n.º 1
0
    void Update()
    {
        UpdateAnimator();
        if (!IsDead)
        {
            GravityActive(true);
            HorizontalMovement();
            VerticalMovement();
            ClimbLadder();
            WallClinging();

            // If the player is dashing, we cancel the gravity
            if (_controller.State.Dashing)
            {
                GravityActive(false);
                _controller.SetVerticalForce(0);
            }

            if (!_controller.State.Firing)
            {
                _controller.State.FiringStop = false;
            }

            if (_controller.State.CanJump)
            {
                if (_controller.State.IsGrounded)
                {
                    _controller.State.CanDoubleJump = true;
                }

                // If the user releases the jump button and the player is jumping up and enough time since the initial jump has passed, then stop jumping
                if ((_jumpButtonPressTime != 0) &&
                    (Time.time - _jumpButtonPressTime >= _controller.Parameters.JumpMinimumAirTime) &&
                    (_controller.Velocity.y > Mathf.Sqrt(-_controller.Parameters.Gravity)) &&
                    (_jumpButtonReleased) &&
                    (!_jumpButtonPressed || _controller.State.Jetpacking))
                {
                    _jumpButtonReleased = false;
                    _controller.AddForce(new Vector2(0, 12 * _controller.Parameters.Gravity * Time.deltaTime));
                }
            }
        }
        else
        {
            _controller.SetHorizontalForce(0);
        }
    }
Exemplo n.º 2
0
 public void ControllerEnter2D(CorgiController2D controller)
 {
     controller.State.CanDoubleJump = false;
     controller.SetVerticalForce(Mathf.Sqrt(2f * JumpPlatformBoost * -controller.Parameters.Gravity));
 }