Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Xian |
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?
// 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("walking")
else:
print("run run")
pass
func _on_TouchScreenButton_released():
$Timer.start(0.5)
walk = false
pass
func _on_Timer_timeout():
walk = true
$Timer.stop()
pass
ramazan | 2022-03-23 15:10
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):
or
func _on_action_released(input):
as far as I know. There is only a method called
Input.is_action_pressed("ui_right")
But I dont know any ways to intercept it. So using this method will make the script really long.
Xian | 2022-03-23 23:09