- Edited
So basically im trying to get an animation to play on a certain event for a set amount of time before swapping back to idle, i use an await timer but when I use this await timer it stays going so if an animation plays during the timer of the last animation it will swap back to the idle before the time that the animation was intended to swap back
The code is this
func _on_area_2d_body_entered(body):
if "Left" in body.name:
body.queue_free()
animated_sprite_2d.animation = "Left"
await get_tree().create_timer(.15).timeout
animated_sprite_2d.animation = "Idle"
elif "Down" in body.name:
body.queue_free()
animated_sprite_2d.animation = "Down"
await get_tree().create_timer(.15).timeout
animated_sprite_2d.animation = "Idle"
elif "Right" in body.name:
body.queue_free()
animated_sprite_2d.animation = "Right"
await get_tree().create_timer(.15).timeout
animated_sprite_2d.animation = "Idle"
elif "Up" in body.name:
body.queue_free()
animated_sprite_2d.animation = "Up"
await get_tree().create_timer(.15).timeout
animated_sprite_2d.animation = "Idle"