Animation cycles on keypress?

Godot Version



Hii! I’m very new to Godot, I only started coding some days ago and so far it’s been very intuitive!

I’m working on a simple 2D platformer with my own art, and so far, I got my idle, walking and jumping animations working perfectly

I’m currently working on a crouching animation, I have my “Crouch_Down” animation, then my “Crouch_Hold” animation, and my “Crouch_Up” animation

I want this to happen:

-Play “Crouch_Down” when you press ‘S’
-When that’s done, switch to “Crouch_Hold”
-Loop that until you release ‘S’
-Play “Crouch_Up” on release
-Switch back to idle as soon as “Crouch_Up” ends

I’m using the basic “Sprite2D” for everything and every animation is played like this one:

if is_on_floor() and is_crouching:
sprite_2d.animation = “Crouch_Down”

Is there a way to do what I’m envisioning with what I have?

Thanks! :slight_smile: