Animation issue
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 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?
- Edited
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?
- Edited
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.
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.
- Edited
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.
Thank you everyone! I figured it out.