Topic was automatically imported from the old Question2Answer platform.
Asked By
lavaduder
Okay I recently found out about the match flow control keyword. I’m wondering how one would implement this into _input. As ifelse ladders are weary, and look ugly.
func _input(event):
match event.as_text():
"A":
do_something()
"W":
do_something_else()
But event.as_text() won’t give you the name you’ve defined in the input map. If you press the W key, it will return “W”, so i don’t know how useful this would be.
However it looks like you could simplify what you have currently by a little bit:
When setting p.vel.z = 0, i don’t think you need to check if it is -1 or 1, because the alternative is that it is 0, and if that is the case, setting it to 0 again won’t hurt anything.
I do need to check if the input has been released is -1 or 1.
Why?
Say we go with this code. If the right input was released. The vel would remain 1, and the character would keep moving. (Unintended Ice physics.)
The main reason why I compare the vel. is to ensure that when left key is released, and vel is going right. That it won’t suddenly stop. Only stop going right when the right key is lifted.