@TwistedTwigleg said:
Are you overriding the animation anywhere by calling $AnimationPlayer.play
before playing the crouch animation? Like an idle animation or something similar? It is probably something is overriding the animation, so it keeps switching back and forth between the overriding animation and the crouch animation, which makes the crouch animation stuck on just the first frame.
I don't think so? I mean, the character visibly crouches, so it seems like it's transitioning to it, it's just not playing. Here's the full code in case that might help:
extends KinematicBody2D
export var walkSpeed : int;
export var runSpeed : int;
export var jumpSpeed : int;
export var gravity : int;
export var maxFallSpeed : int;
export var health : int;
var crouching = false;
var attacking = false;
var velocity : = Vector2();
func input():
#Movement
if Input.is_action_pressed("right") and !crouching:
$Sprite.flip_h = false;
if Input.is_action_pressed("run"):
velocity.x = runSpeed;
$AnimationPlayer.play("Run");
else:
velocity.x = walkSpeed;
$AnimationPlayer.play("Walk");
elif Input.is_action_pressed("left") and !crouching:
$Sprite.flip_h = true;
if Input.is_action_pressed("run"):
velocity.x = -runSpeed;
$AnimationPlayer.play("Run");
else:
velocity.x = -walkSpeed;
$AnimationPlayer.play("Walk");
else:
velocity.x = 0;
$AnimationPlayer.play("IdleStand");
#Jump
if is_on_floor() and Input.is_action_pressed("jump"):
velocity.y = -jumpSpeed;
$AnimationPlayer.play("Jump");
#Crouch
if is_on_floor() and Input.is_action_pressed("crouch"):
crouching = true;
$AnimationPlayer.play("Crouch");
else:
crouching = false;
func _physics_process(delta):
input();
velocity.y += gravity * delta;
if velocity.y > maxFallSpeed:
velocity.y = maxFallSpeed;
move_and_slide(velocity, Vector2.UP);