(SOLVED) Is it possible to make a character walk (using arrow keys) and run (holding a button down while using arrow keys)?

Before proceeding, please use the forum search feature at the top of the page to check if your question has already been answered.

How do I…

Press and hold a button within GDevelop’s events?

What is the expected result

I want to give my character the ability to walk AND run. For walking, I have animations for my character when he walks in four directions (up, down, left, right). Mapping those to the arrow keys was easy, but I was thinking of giving him run animations when you hold a button down WHILE using the arrow keys to make him move around faster.

Undertale :heart:, Chrono Trigger, and Final Fantasy IV (to name a few) have been games that I played that allowed this and I was hoping that this would be possible in GDevelop.

What is the actual result

I made an animation for him running and within GDevelop, I made a sub-event and tried using the “button pressed” condition, then tried the “change animation” action and while he moves when I hold the button down, he doesn’t do the run animation that I made for him, at all.

Related screenshots

Ok
Left arrow key pressed = Make player run
Shift key pressed

I tried that and he doesn’t do the animation I made for him when he’s running.

I only made one animation for him running down to see how if this would work and still nothing.

Hey,

I think the animation is not playing because while both the arrow AND x buttons are pressed, the animation keeps changing back and forth between Walking and Running.

You can build your events to this:

down is pressed

  • (invert) x is pressed → change animation to Walking
  • x is pressed → change animation to Running

Some extra notes:

  • remove the event (player is moving → activate platformer behavior). Since the player won’t be able to move if the behavior is not activated, so the event is useless.
  • replace the condition any key is released with (invert) player is moving.
1 Like

I tried what you suggested, but for some reason, when I’m not pressing anything, my character just walks in place. I want him to do his idle animation when no button is pressed.

Instead of checking if no key is pressed or any key is released which is not the best approach and can cause unwanted behaviors, inverting the player is moving condition makes it player is NOT moving.

(invert) player is moving → change animation to idle.

1 Like

Thanks for your help. :heart:
It’s working great, though his running speed is the same as him walking for some reason.

Update: I found out about the max speed action in the events and I’m using that for my character’s speed.

You’re welcome!

Yes max-speed is how you implement sprinting. The way I do it in my events:

  • (invert) x is pressed → max-speed = 100
  • x is pressed → max-speed = 200
1 Like