rolling animation

Godot Version

4.3

Question

so im trying to give my character a roll animation but it just doesnt work no matter how much i tried. everything except that god damn roll works
heres the code:
if is_on_floor():
if direction==0:
animated_sprite_2d.play(“idle”)
else:
animated_sprite_2d.play(“run”)
else:
animated_sprite_2d.play(“jump”)
if Input.is_action_just_pressed(“roll”):
animated_sprite_2d.play(“roll”)

Hello can you please format your code and tell us about the error you’re encountering?

You can format your code with 3 back tick above and below it (```) or by pressing the format code button and pasting it there.

1 Like

Input.is_action_just_pressed() method returns true for only 1 frame when the action is pressed, then next frame it will be back to returning false. What that means in your code is that when you press your “roll” action, it will register and start playing the “roll” animation, but immediately the next frame it will go back to one of your other animations - “idle”, “run” or “jump” respectively.

How to fix it depends on what you want to actually achieve.
E.g.
Do you want to play “roll” animation for as long as you are pressing the “roll” action?
Do you want to play “roll” animation when you press the “roll” button and not allow any of the other animations to be played as long as the “roll” is playing?

2 Likes