I've been attempting to make a system in which you can use an ability with 3 charges. Once you use one, Only that one will recharge, When you use another, The recharge progress from the first will go to the second one, etc. I, However, Have not been able to accomplish this.
Attempted: Using conditionals and awaits to create cooldowns based off of the amount of charges currently left
Result: Charges going above the maximum wanted amount when using charges before full recharge.
extends RigidBody2D
@export var RotationSpeed = 4.2
@export var JumpPower = 1000
@onready var jumpcount: int = 3
@onready var timerRunning: bool = false
var animationTime: float
var continue1: bool = true
var continue2: bool = true
func _ready():
Gwobaw.Player = self
$Sprite2D/GPUParticles2D.z_index = -5
$Sprite2D/GPUParticles2D.emitting = true
func Jump():
if(jumpcount > 0):
if $RayCast2D.is_colliding():
var enemy = $RayCast2D.get_collider()
enemy.Health -= 100
linear_velocity = -transform.y * JumpPower
$Sprite2D/GPUParticles2D.emitting = true
$Sprite2D/GPUParticles2D.z_index = -1
jumpcount -= 1
func _process(delta):
$CanvasLayer/Label.text = str(jumpcount)
if Input.is_action_pressed("ui_right"):
angular_velocity = RotationSpeed
if Input.is_action_pressed("ui_left"):
angular_velocity = -RotationSpeed
if Input.is_action_just_pressed("Boost"):
if(jumpcount == 3):
Jump()
await get_tree().create_timer(5).timeout
if(continue1 == true):
jumpcount -= 1
elif(jumpcount == 2):
Jump()
continue1 = false
await get_tree().create_timer(5).timeout
if(continue2 == true):
jumpcount += 1
await get_tree().create_timer(5).timeout
jumpcount += 1
continue1 = true
elif(jumpcount == 1):
continue2 = false
Jump()
await get_tree().create_timer(5).timeout
jumpcount += 1
await get_tree().create_timer(5).timeout
jumpcount += 1
await get_tree().create_timer(5).timeout
jumpcount += 1
continue2 = true