Jetpack up and double press

I want to make a function that I can call in physics_process function, which when you press double space, the second press will make the character use a jetpack and go up and play jetpack_up animation (or I don’t know how particles work but if it is easier how can I do that). I have a const jetpack_fuel with number 100 and I want to make it consumed when this movement happens. here is the complete code: (thank you for your time in advance)

extends CharacterBody2D

var speed = 200
const jump_velocity = -400
var direction = Vector2()
const jetpack_fuel = 100
@onready var sprite_2d = $Sprite2D

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var animation = 'idle'

func _jetpacking():
	
func _jumping_animation(): 
	if not is_on_floor():
		animation = 'jumping'
func _walking_n_running():
	direction = Input.get_axis("GoLeft", "GoRight")
	if direction != 0:
		velocity.x = direction * speed
		if speed > 200:
			animation = "running"
		else:
			animation = "walking"
	else:
		velocity.x = move_toward(velocity.x, 0, 16)
		if is_on_floor():
			animation = "idle"	
func _jump(delta):
	if not is_on_floor():
		velocity.y += gravity * delta
	elif Input.is_action_just_pressed("Jump") and is_on_floor():
		velocity.y = jump_velocity
func _running():
	if Input.is_action_pressed('Sprint'):
		speed = 280
	else:
		speed = 200
func _flip():
	if Input.is_action_just_pressed('GoLeft'):
		sprite_2d.flip_h = true
	if Input.is_action_just_pressed('GoRight'):
		sprite_2d.flip_h = false


func _physics_process(delta):
	_jump(delta)
	_walking_n_running()
	_running()
	_flip()
	_jumping_animation()
	move_and_slide()
	
	sprite_2d.animation = animation

You will have to make jetpack_fuel a var to be able to change it. Currently you check if the player pressed jump and they are on the floor to jump, could you do the jetpack if they press jump and not on the floor?

What should I write into the function named jetpacking (I changed the const to var)

For the jetpack particles you need a GPUparticles3D node.

The jetpacking function could be something like this:

func _jetpacking(delta):
	if jetpack_fuel <= 0:	# no fuel -> can't jetpack
		return
	velocity.y = jump_velocity # or jetpack_velocity ?
	jetpack_fuel -= delta
	jetpack_particles.emitting = true
	animation = "jetpacking"

And I’d add it to the _jump function like this (but I haven’t tested so not 100%…):

func _jump(delta):
	if is_on_floor():
		if Input.is_action_just_pressed("Jump"): # normal jump
			velocity.y = jump_velocity
	else:
		if Input.is_action_pressed("Jump"): #jump pressed in air
			_jetpacking(delta)
		else:
			velocity.y += gravity * delta # jump not pressed -> falling
			animation = 'jumping'

I also added the jumping animation here because if it’s a separate function it might interfere with the jetpacking animation, so you’s have to remove the _jumping_animation function.

The particles should be set to one shot for this to work, so it would emit a small amount of particles every frame while you’re jetpacking.
But I don’t know how you want to do that so if that’s not how you want it to work then that part of the code will need a bit more work, to enable and disalbe emitting…