Double tap system

Godot Version

4.5.1

Question

I am trying to implement a double tap then hold feature but only the last nested if statement isn't working for some reason despite the values showing to be true when debugging yet the elif statement runs perfectly fine

Please bear with me, I am pretty bad at programming and I feel this may not even be a good way to handle this feature

_portal_state_setter(delta)

runs match cases for the respective enum PlayerPortalState values (TAP, IDLE, HOLD

	if not is_grounded:
		if player_jumped == true:
			if Input.is_action_pressed("jump"):
				Input.action_release("jump")
				
			if Input.is_action_just_released("jump"):
				player_second_tap = true
				player_current_state = PlayerPortalState.TAP
                print("jump released")
				
			if Input.is_action_pressed("jump") and player_second_tap == true:
				print("activating...")
				air_time += delta
				if air_time > 0.15:
						player_current_state = PlayerPortalState.HOLD
						print("val set to on from elif")
		#elif player_jumped == false:
			#if Input.is_action_pressed("jump"):
				#air_time += delta
				#if air_time > 0.15:
						#player_current_state = PlayerPortalState.HOLD
						#print("val set to on from playjump false")
		_portal_state_setter(delta)

What is it that sets player_jumped?

I’d think it would be easier to have your jump/double tap detect look something like:

if is_grounded:
  if Input.is_action_just_pressed("jump"):
    player_jumped = true
    jump_presses  = 0
else: # !is_grounded
  if Input.is_action_just_pressed("jump")
    jump_presses += 1
    if jump_presses == 1:
      # double tap here
# make sure you clear player_jumped when they land...

You could add a time constraint fairly easily if you want, by taking the time at the first press and checking it against the time of the second press.

player_jumped is true if the player was grounded i.e physically colliding with the ground and the jump button is pressed.

The conditions are inside not is_grounded because I wanted the input to be different when the player walks off the platform rather than jumping off so there are two different outcomes when the player is not grounded but wants to perform the action.