Exemplo n.º 1
0
    private bool HandleJumpEvent()
    {
        if (!JumpDragging)
        {
            return(false);
        }

        if (!_jumper.CanJump())
        {
            if (_jumper.TrajectoryInUse())
            {
                _jumper.CancelJump();
            }
            return(false);
        }

        if (DashStart)
        {
            HandleTrajectoryInit <ChargeTrajectory>();
            _jumpDragInitialized = false;
            _dashInitialized     = true;
        }
        else if (!Dashing && !_jumpDragInitialized)
        {
            HandleTrajectoryInit <ClassicTrajectory>();
            _dashInitialized     = false;
            _jumpDragInitialized = true;
        }

        _jumper.Trajectory.DrawTrajectory(_hero.Transform.position, _joystick2.Direction);

        return(true);
    }
Exemplo n.º 2
0
    void FixedUpdate()
    {
        //caching the horizontal input
        float _h;

        //assign value based on left or right input
        if (CustomInput.Left)
        {
            _h = -1f;
        }
        else if (CustomInput.Right)
        {
            _h = 1f;
        }
        else
        {
            _h = 0f;
        }


        // If the player is changing direction (h has a different sign to velocity.x) or hasn't reached maxSpeed yet...
        if (_h * rigidbody2D.velocity.x < _maxSpeed)
        {
            //account for air control
            if (_jumper.CanJump())
            {
                rigidbody2D.AddForce(Vector2.right * _h * _moveForce);
            }
            else
            {
                rigidbody2D.AddForce(Vector2.right * _h * _moveForce * _airControl);
            }
        }

        // If the player's horizontal velocity is greater than the maxSpeed...
        if (Mathf.Abs(rigidbody2D.velocity.x) > _maxSpeed)
        {
            // ... set the player's velocity to the maxSpeed in the x axis.
            rigidbody2D.velocity = new Vector2(Mathf.Sign(rigidbody2D.velocity.x) * _maxSpeed, rigidbody2D.velocity.y);
        }

        //flippng based on direction and movement
        if (_h > 0 && !_facingRight)
        {
            Flip();
        }
        else if (_h < 0 && _facingRight)
        {
            Flip();
        }

        //if jump was pressed
        if (_jump)
        {
            //and player can jump
            if (_jumper.CanJump())
            {
                //add upward force
                rigidbody2D.AddForce(new Vector2(0f, _jumper.Force), ForceMode2D.Impulse);
            }
            _jump = false;
        }
    }