Need help with animation

Hey, i’m trying to make it so,

When you click a button, the ‘throw’ animation plays for 10 seconds. When the animation has passed 5 seconds, you have a 5 second window to press F, which should then play the ‘catch’ animation. If you do not press F within the last 5 seconds, the animation goes back to ‘idle’. How do I do that?

Your question is a bit sparse on details. I’ll assume you’re using a AnimatedSprite2D and already know how to create a Button/Timer node and connect their signals:

var can_catch := false

func _on_timer_timeout() -> void:
	# flip the booleans value
	can_catch = not can_catch

	if can_catch:
		$Timer.start()
		print("Press F to catch!")
	else:
		$AnimatedSprite2D.play("idle")
		print("Time's up, sorry!")


func _input(event: InputEvent) -> void:
	if event is InputEventKey and event.keycode == KEY_F and event.pressed:
		if can_catch:
				$AnimatedSprite2D.play("catch")


func _on_button_pressed() -> void:
	if $AnimatedSprite2D.animation == "idle":
		$AnimatedSprite2D.play("throw")
		$Timer.start()

(The timer’s wait_time is set to 5 seconds)

1 Like