Jump Height Inconsistant

I’m making a 2d platformer with variable jump height. This means that if you hold the button you will jump higher than if you just tap it. I’m running into an issue that really confuses me. Essentially, sometimes the player will do a very springy leap, and at times they will barely leave the ground. While digging through my code, I’ve found that this is directly proportional to framerate, e.g when I have altered the time value in unity settings, the player’s jump will be drastically reduced. This is so extreme that while I had my recording software open to record the anomaly, it altered my framerate and made my character do a much larger jump than normal (I am on a mac with low processing power). Thanks!



//For Jumping	
	private void doJump()
	{
		coyoteFloating = false;
		
		if (jq == jumpQueueLength)
		{
			jq = 0;
			jumpQueued = false;
		}

		//Player has hit head on a ceiling; cancel jump
		if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsCeiling))
			i = jumpDuration;

		//Let go before peak of jump; Apply final force
		if (!isPressed && i < jumpDuration && !m_Grounded)
		{
			jumpingAndReleased = true;
			i = jumpDuration;
			m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, jumpReleaseForce);
		}

		//Being held and less than full jump height; Apply consistant upwards force
		if (isPressed && i < jumpDuration && !jumpingAndReleased)
		{
			m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, jumpForce);
			i++;
		}

		if (i == jumpDuration && !hasAppliedFinalJumpForce && !m_Grounded)
		{
			m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, jumpReleaseForce);
			hasAppliedFinalJumpForce = true;
			Debug.Log("Applied");
		}

		//If last frame the player was moving up and this frame the player is moving down, we are at the peak
		if (velocityLastFrame > 0f && m_Rigidbody2D.velocity.y <= 0f)
		{
			animationManager.peak = true;
			animationManager.launch = false;
			jumpQueued = false;
		}

		velocityLastFrame = m_Rigidbody2D.velocity.y;
	}

When doing physics operations, you will likely have to play a bit with both Update and FixedUpdate. If your input is in Update and the resulting physics commands are in FixedUpdate, or everything is in Update, it’s possible that multiple FixedUpdate calls are being called on a single input, or not at all.

One thing you can try is to look for Inputs in Update, and let that set a variable boolean or timer/timestamp. Then, when FixedUpdate is called, let that “consume” that variable and make it be ready for the next Input. This will prevent putting in multiple inputs when you only intended for one per amount of time.