Godot Version
4.2.2
Question
I have character animations when it goes back and forth and want to add another one when it gets a damage, but the damage animation plays way too quickly since I bound right and left animations to key press it happens instantly. But when I don’t press any keys, it plays as it should be.
if Input.is_action_pressed("right"):
$AnimatedSprite2D.animation = "walk"
$AnimatedSprite2D.flip_h = true
elif Input.is_action_pressed("left"):
$AnimatedSprite2D.animation = "walk"
$AnimatedSprite2D.flip_h = false
elif velocity == Vector2.ZERO:
$AnimatedSprite2D.animation = "idle"
#if lost all lives then game over
if lives.get_child_count() == 0:
Engine.time_scale = 0.5
$CollisionShape2D.disabled = true
$AnimationPlayer.play('death')
rotation_degrees = 45
await get_tree().create_timer(0.3).timeout
get_tree().reload_current_scene()
Engine.time_scale = 1.0
I am adding it here as it is the only place when I can catch the life lost:
level.connect("enemy_collision", loosing_health)
# erasing life icons if collided with enemies
func loosing_health():
$AnimatedSprite2D.animation = "damaged"
lives.get_child(lives.get_child_count() - 1).queue_free()
When I add await, it throws an error because I am reloading the scene when there is no life left
How to make it play just a fraction of second?