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