Move a sprite with key (Shake a bag)

Godot Version:
4.3

Question
I drew a bag and animated it- I want it to use my shake animation when I press space and idle when I’m not. Can anyone help me as I tried earlier but couldn’t figure it out. Thanks

You could play the animation when the action is pressed and stop when the action is released

func _input(event: InputEvent) -> void:
	if event.is_action_pressed("shake"):
		$AnimationPlayer.play("shake_loop")
	elif event.is_action_released("shake"):
		$AnimationPlayer.stop()

I tried that but still nothing- Anything else I need?

Nothing in your scene as you’ve shown it has a script. Try attaching this script to “Baggy”

So now it plays the animation for “Shake” but when I let go it keeps playing the animation

You are also asking it to stop when you release a different action “Idle”.

1 Like

Oh I fixed that. Thank you for your help!