The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hello, it sounds confusing since I don't know how to describe it well. You know those games that when you hold down an arrow key it'll make the player walk but when you press, release, and hold that arrow key in certain games it'll instead make the player run

To give an example:
I want that when I hold the "ui_right" action, the player will walk to the right.

input = →(Hold) 

And when I pressed the action then quickly release then press and hold the "ui_right" action again, the player will run to the right.

input = → , →(Hold)

So how do I detect when such sequence happens?

Godot version 3.4.3 stable
in Engine by (271 points)

// add TouchScreenButton
// add Tİmer
// and don't forget = Project > Project Settings > General > Input Devices > Pointing set Emulate Touch From Mouse to On

var walk = true

func _on_TouchScreenButton_pressed():
  if walk == true:
     print("run run")

func _on_TouchScreenButton_released():
  walk = false

func _on_Timer_timeout():
  walk = true

thanks but this does not work for all cases. I'm using input mapping so that this game will work on windows pc, android, and linux and can use an external controller so when setting up using the key mapping menu. There is no equivalent

func _on_action_pressed(input):


func _on_action_released(input):

as far as I know. There is only a method called


But I dont know any ways to intercept it. So using this method will make the script really long.

1 Answer

+1 vote
Best answer

Here's one example:

The above version doesn't use a process function either, but I would probably use it because it's intuitive to me. Maybe have a new variable like last_press_timer and set it to the timeout you want (the window where you can double press) and do last_press_timer -= delta in physics_process or something, then the next time the button is pressed check if that timer is <= 0. If it isn't, you should be good to do the double press behavior.

Lots of ways to do this one

by (170 points)
selected by

thanks this is exactly what I need.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.