Problems with changing animations connected to input through GD-script

Godot Version

Godot_v4.6.2-stable

Question

I'm currently making a top-down 2d game as a person who's new to game developing and coding. i'm done with all the 2dAnimatedSprite animations. But the problem is that i'm trying to play a sort of "crawling" animation based on an input, and i'm strugling on how to make it work. As the animations don't change from the walking animations when i press the input to make the sprite "crawl"

Ps. srry if i posted this in the wrong sub-category

_process is called once per frame, and the crawl check is done with Input.is_action_just_pressed. That function will only return true when the action is pressed. If you hold the crawl button and _process gets called again, that same check will return false.

If I can make a suggestion, you should consider refactoring your code to make use of state machines. Unless your character only ever needs to run and crawl, you’ll likely have to add more if-statements to your code, and things will get messy quick. Using state machines will help avoid that problem. If you search the internet for something like “Godot character controller state machine”, you’ll likely find good examples.

On a separate note, it’s considered good practice to post your code as formatted text rather than as images, as this makes reading code much easier.

Thank you for responding on such a short notice, and a further explenation of how _process works! I’ll definetly check out some tutorials, for i’ve never heard of “state machines”!