Hmm, I looking at the code I do not see anything that should be causing the issue.
The only thing I can think of that might be causing the issue is the following code:
if Input.is_action_pressed("ui_down"):
if on_ground == true:
velocity.x = 0
$AnimatedSprite.play("duck")
duck = true
else:
duck = false
if Input.is_action_pressed("ui_down") == true && Input.is_action_pressed("ui_right"):
velocity.x = SPEED * 0.3
if $AnimatedSprite.animation != "crawl":
$AnimatedSprite.play("crawl")
$AnimatedSprite.flip_h = false
crawl = true
elif Input.is_action_pressed("ui_down") == true && Input.is_action_pressed("ui_left"):
velocity.x = -SPEED * 0.3
if $AnimatedSprite.animation != "crawl":
$AnimatedSprite.play("crawl")
$AnimatedSprite.flip_h = true
crawl = true
else:
crawl = false
I wonder if what is happening is that the duck animation is being played before the code for crawling is executed. If that is the case, then the animation would change to duck before changing to crawl shortly after.
If this is the issue, then the reordering the code should, hopefully, fix the issue.
if Input.is_action_pressed("ui_down"):
if on_ground == true:
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED * 0.3
if $AnimatedSprite.animation != "crawl":
$AnimatedSprite.play("crawl")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
velocity.x = SPEED * 0.3
if $AnimatedSprite.animation != "crawl":
$AnimatedSprite.play("crawl")
$AnimatedSprite.flip_h = true
else:
velocity.x = 0
$AnimatedSprite.play("duck")
duck = true
else:
duck = false
else:
crawl = false
I'm not sure if my earlier code for checking the animated sprite is needed anymore, so if this fixes the issue you might want to see if removing it does anything.
But other than the duck animation playing before the code for the crawl animation, I do not see anything that would be causing the issue. I'll try to take another look tomorrow, maybe that will help.
Using an animation tree might be the way to go, though I have not used it in Godot so I'm not totally sure.