Walking Anim not Animing

Hello. I’m currently working on a small platformer parkour thingy thing out of sheer boredom (yes I’m irresponsible and a pro at procrastinating). I have this teeny tiny problem where if I press the left and right keys at the same time, the walking animation keeps playing. What’s more is that after doing that when I release the left key (or right key) while holding down right (or left) the sprite just gives up and does a moonwalk with no animation. https://arcade.makecode.com/S50277-96601-19250-13232

I’m not a professional coder or anything so please leave out the technical stuff thanks.
I just wanna create a basic module that I can build on if I ever want to make a serious coding game.

help please

3 Likes

Hope this helps: https://arcade.makecode.com/S28660-12229-56084-99729

Use the character animations extension, you can do stuff like animate with animation when moving right.

1 Like

use if _ button is released set mysprite animation to idle animation

If you think about what’s happening, step by step, your issue is that the buttons don’t care if the other of the two is pressed or not. For example, you press left and your character moves left, then you press right and all the animation code just assumes that left is no longer pressed and starts the animation for walking right, even though the left button is still held down.

Instead of adding more logic to fix this, I would recommend stripping down the logic and not using On Button Pressed/Released blocks at all. I would use a single Forever block, combined with those < Is Button Pressed > Boolean blocks from the Controller blocks tab and some IF blocks. Then, because animations look frozen if you constantly restart them, I would have a variable to keep track of which animation is playing and not restart the animation if the correct one is already playing.

That might be a lot, so here is some sudo code:

“anim_playing” is 0 if none is playing, 1 if the right animation is playing, and 2 if the left one is playing

Forever:

If ( < is Left button pressed > = < is Right button pressed > ):

If ( anim_playing ): stop animations and face a direction based on what value anim_playing is.

Else if ( < is Right button pressed > ):

If ( anim_playing =/= 1 ): anim_playing = 1, start walking right animation

Else:

If ( anim_playing =/= 2 ): anim_playing = 2, start walking left animation

P.S. You can use variables in IF blocks without “ = true” part. Just put the variable in. Use the “< Not <> >” block to check for false. Number variables will be “false” if 0, and “true” if anything else, which is how that “If ( anim_playing )” part is checking that the variable isn’t 0, because if an animation was playing the number would be “true” because the number wouldn’t be 0.

The first If statement works because if both left and right pressed are False, then they are equal and the stop animation code runs, and if they are both true, that means they equal and the stop animation code runs, which is very convenient.

3 Likes

thanks

1 Like

never thought to use the extensions lol

makes things much easier

1 Like

That sounds great, and is probably what character animations is already doing

1 Like