The animations on my character arent playing, any help?

Godot Version

4.2.2

Question

It just plays a random frame of a animation and just stops, it doesnt play the run animation or jump or anything.


class_name PlayerAnimatedSprite

var frame_count = 0
func trigger_animation(velocity: Vector2, direction: int, player_mode: Player.playermode):
    var animation_prefix = Player.playermode.keys()[player_mode].to_snake_case()
    
    if not get_parent().is_on_floor():
        play("%s_jump" % animation_prefix)
    
    #handle slide animations
    elif sign(velocity.x) != sign(direction) && velocity.x != 0 && direction != 0:
        play("%s_slide" % animation_prefix)
        scale.x = direction
    else:
    # handle the sprite direction
        if scale.x == 1 && sign(velocity.x) == -1:
            scale.x = -1
        elif scale.x == -1 && sign(velocity.x) == 1:
            scale.x = 1
        
        # handle run and idle animations
        if velocity.x != 0:
            play("%s_run" % animation_prefix)
        else:
            play("%s_idle" % animation_prefix)```

I guess your class extends an AnimatedSprite2D? Where do you call trigger_animation? If you do it in _process or _physics_process, you’ll restart the animation every frame (i.e. not see any animation to begin with).