Hello everyone,

I'm quite new to godot and I've run into an issue with animating my player character. The idle animation works fine, but when I try to move left or right, the character moves while being stuck in the first frame of the run animation. The strange thing is, the run animation works perfectly while I am in midair after falling off a platform, but it goes back to the 1st frame and stays there the instant the player hits the ground. I also have a jump_right animation that is supposed to play when the jump and right buttons are pressed at the same time, but I can't seem to get that working either. Any advice would be greatly appreciated. Thank you all!

  • xyz replied to this.

    Derek9132 On each frame you start playing the idle animation and then immediately switch to run animation. This effectively re-starts the run animation each frame.

      xyz Where might the code that handles these frames be? I know that in Unity there is an update method that runs once per frame, but I don't see anything like that here. Thanks for your help!

      • xyz replied to this.

        xyz I see. So if _physics_process() runs once per frame, then the code for the running animations should be outside of the _physics_process() function so that it is separate from the idle animation. Am I on the right track?

        I think the problem is that the "Run_right" and "Run_left" animations are not played in response to an is_action_just_pressed event. Their playing is restarted continuously (60 times per second) based only on velocity.x.

          DaveTheCoder Sorry, could you clarify what you mean by that? The Jump animations are within a conditional that checks if the right input is being pressed and plays the jump_left animation otherwise. Although the run_right and run_left animations are not in response to an _is_action_just_pressed and use velocity.x like you said in your comment. Am I right to assume you meant to put run_right and run_left instead of jump_right and jump_left? Also, thank you for this advice. So if I put the code for playing the running animations in response to a conditional _is_action_just_pressed, it should work, correct?

            Derek9132 There's nothing technically wrong with your code. You just need to put everything together using the proper logic. Here's how stuff works:

            • _physics_process() is executed automatically every physics frame (by default 60 times per seconds)
            • Input.is_action_just_pressed() returns true if an action went down in the current frame. Otherwise returns false.
            • AnimationPlayer::play() will do nothing if you tell it to play the animation that's already playing. It'll just continue playing the current animation. If you tell it to play any other animation, it will cease the current animation and play the new animation from the start.

            Now you have all the ingredients to cook up the right execution flow 😉

              Derek9132 Am I right to assume you meant to put run_right and run_left instead of jump_right and jump_left?

              Yes. I just edited my post to correct that.

              xyz _physics_process() is executed automatically every frame.

              Every physics tick, _process() is executed every frame.

              • xyz replied to this.

                Megalomaniak Right, I tend to call it 'physics frame' instead of 'physics tick'.
                Anyway, they'd likely coincide for default settings on a typical system.

                  xyz I tend to call it 'physics frame' instead of 'physics tick'.

                  Yeah, used to do the same, but realized just how confusing that can be. I recon it's important to distinguish the difference between process and physics process.

                  • xyz replied to this.

                    Megalomaniak Sure, but it's not really relevant in this context. I corrected it in the above post though 😉.

                      xyz Yes, but my thinking here was more in terms of others might come across the topic in their searches too, or the OP might recall this 6 months later, but end up mixing the two up.