i made a part of a script that's meant to make a running animation play when holding the "run" key down while pressing the basic movement keys, "left" and "right", but only ends up having the running animation play the first frame (out of six, in case it might matter).

EDIT: the full running animation only plays when falling

this is the code used to make the animations play (uses AnimatedSprite2D for animations):

func update_animations(input_axis):
if is_on_floor():
if Input.is_action_pressed("right") or Input.is_action_pressed("left"):
$AnimatedSprite2D.play("walk")
else:
$AnimatedSprite2D.play("idle")
if Input.is_action_pressed("run") && input_axis != 0:
$AnimatedSprite2D.play("run")

  • thatoneguy modified @fatalox's function slightly. Try this

    var running =: false
    
    If !is_on_floor():
      if Input.is_action_pressed("right") or Input.is_action_pressed("left"):
         if !$AnimatedSprite2D.is_playing():
            if running && Input.is_action_pressed("run") && input_axis != 0:
               $AnimatedSprite2D.play("run")
               print("run testing")
            else:
               $AnimatedSprite2D.play("walk")
               print("walk testing")
      else:
         $AnimatedSprite2D.play("idle")
         print("idle testing")

Maybe you can try to set a variable for running.

var running := false

if Input.is_action_pressed("run"):
    $AnimatedSprite2D.play("run")
    running = true
else:
    running = false

    fatalox

    this still makes the animation just stay on the first frame

    also, sorry for the late reply, i posted this at like 1 AM and then fell asleep

      thatoneguy No worries. Lets start from the basic then. Check if in the animation player your "Run" animation have the setting loop ON.
      No, you say that animation "run" plays full when you failling, so it's related to "is_on_floor()".
      Try using ! operator before "is_on_floor()" and see what happen

        thatoneguy Could you also drop a screenshot to you Animation timeline, might help us track down the cause of your issue.

        fatalox

        this somehow makes the run animation not play at all

        (also the loop is on for the run animation)

          thatoneguy I added some "print("Testing)", when code is played you should see in the Output console something when reached.

            thatoneguy modified @fatalox's function slightly. Try this

            var running =: false
            
            If !is_on_floor():
              if Input.is_action_pressed("right") or Input.is_action_pressed("left"):
                 if !$AnimatedSprite2D.is_playing():
                    if running && Input.is_action_pressed("run") && input_axis != 0:
                       $AnimatedSprite2D.play("run")
                       print("run testing")
                    else:
                       $AnimatedSprite2D.play("walk")
                       print("walk testing")
              else:
                 $AnimatedSprite2D.play("idle")
                 print("idle testing")

              thatoneguy Great news! Do you mind flagging my post as the best answer, so it marks the thread for everyone looking in the feed 🙂