Hello,
The game I'm making involves real-time combat on a tile-based grid. I want to make the input-handling for the player as smooth as possible, but I've come across some issues.
When the player taps the button/key, I want the player character to move one tile:
+-----------------------+
| | | | |
| | X | | |
| | | | |
+-----------------------+
+-----------------------+
| | | | |
| | | X | |
| | | | |
+-----------------------+
If the player holds the button/key, I want the player character to move across tiles until they stop holding the button/key:
+-----------------------+
| | | | |
| X | | | |
| | | | |
+-----------------------+
+-----------------------+
| | | | |
| | X | | |
| | | | |
+-----------------------+
+-----------------------+
| | | | |
| | | X | |
| | | | |
+-----------------------+
+-----------------------+
| | | | |
| | | | X |
| | | | |
+-----------------------+
NOTE: If the player taps the button/key several times, they should get the same result as holding the button/key.
Ultimately, I want player movement to be controlled by how long the button/key is held for - but I want it to be throttled to a fixed speed, instead of as-fast as the system can handle player input.
Here's what I've tried so far:
This allows the player to hold the button/key to move, but input comes in too fast and the player character flies across the screen:
func _process(delta):
if Input.is_action_pressed("ui_right"):
emit_signal("moving", "right")
This is more controlled, but does not allow the player to hold the button/key to move. Speed is dependent on player input speed - which is also not ideal:
func _input(event):
if event.is_action_pressed("ui_right"):
emit_signal("moving", "right")
NOTE: In both examples above, signal-handling and player character movement is handled by the combat scene at a higher level.
How can I get the best of both worlds, while also controlling the speed of handling user input?