How do I make my player roll?

Godot Version

Godot v4.3 Windows 11 64-bit
(2D game)

Question

How do I make the 2d sprite play the “roll” animation from the animationplayer when the S key is pressed?

Like this:

func _physics_process(delta):
    if Input.is_action_just_pressed("s"):
        $AnimationPlayer.play("roll")

Note that you need to add the Action “s” to the Input-Map in the Project settings and if you have other animations that are playing you have to make sure to not override this one

I put the code you said in, but it still doesn’t work. I have added the action “Roll” into Input-map and set the input as “s” or “down arrow”. Maybe the other animations playing are overriding it, such as the Idle animation, but I don’t know how to stop that. Heres the player script code, could you check it out please?

Yes since you use an animatedsprite2d you have to call play on that node.
And yes your animation will get overriden, which is why you should take a look at state-machines (There are a bunch of tutorials on youtube). This allows you to easily manage animations and code

Okay, I’ll check out state machines on youtube then. Thanks for the help!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.