Holding jump button = higher jump

Hello dear friends,

I stumbled upon a problem in my script. I am trying to make character jump higher accordingly to how long jump button was held. This is part of code which should be doing so:

    public void JumpControl()
    {
        if (landed  Input.GetButton("Jump"))
        {
            jumpHold -= Time.deltaTime;

            jumpVelocity.y += 0.1f;

            if (Input.GetButtonUp("Jump") || jumpHold < 0.0f )
            {
                rigidbody.AddForce(jumpVelocity, ForceMode.VelocityChange);
                landed = false;
                jumpVelocity.y = 10.0f;
                jumpHold = 0.5f;
            }
        }
    }

But as you can probably guess, it is not working as I planed it to work. It feels like AddForce gets executed only when jumpHold variable satisfies condition jumpHold < 0.0f. Any ideas how to fix this problem? :face_with_spiral_eyes:

Your inner if statement is only reached when the Jump Button is hold (because of the outer if statement).
Get it out of there and it should work.

Makes sense… Will try, thanks :wink: