Godot Version
4
Question
i have a cooldown var, but its not working, i can just spam the keybind and it still runs.
i will paste the code
func _process(delta):
if Input.is_action_pressed("Attack"):
if Is_Attacking == false:
Attack()
if Is_Attacking == false:
Player_Movement() #Every Frame it will go through the player movement function, if player is pressing any of the buttons then the player will get a velocity for the direction there facing.
func Player_Movement():
if Input.is_action_pressed("ui_right"):
player_sprite.flip_h = false
player_sprite.play("Idle_Side")
velocity.x = Speed
velocity.y = 0
elif Input.is_action_pressed("ui_left"):
player_sprite.flip_h = true
player_sprite.play("Idle_Side")
velocity.x = -Speed
velocity.y = 0
elif Input.is_action_pressed("ui_down"):
player_sprite.play("Idle_Front")
velocity.y = Speed
velocity.x = 0
elif Input.is_action_pressed("ui_up"):
player_sprite.play("Idle_Back")
velocity.y = -Speed
velocity.x = 0
else:
player_sprite.play("Idle_Front")
velocity.y = 0
velocity.x = 0
move_and_slide()
func Attack():
if Is_Attacking == false:
animation_player.play("new_animation") # This is the attack animation it would not let me change the name.
swing.play()
Is_Attacking = true
if Enemy == null:
print("No enemy")
else:
print(Enemy,Enemy.Health)
Enemy.Health -= Damage # take the damage var away from the health var
Enemy.modulate = Color(253, 254, 255)
await get_tree().create_timer(0.1).timeout
Enemy.modulate = Color(1,1,1)
Enemy.get_node("Hit").play()
await get_tree().create_timer(0.3).timeout
Is_Attacking = false
player_sprite.play("Idle_Front")
await get_tree().create_timer(0.4).timeout
Is_Attacking = false
if anyone could help that would be nice, thank you.