if event is InputEventKey:
if event.scancode == KEY_F and flashlight.visible == false:
flashlight.show()
elif event.scancode == KEY_F and flashlight.visible == true:
flashlight.hide()
the problem as you guessed is that the light doesn’t stay visible and flickers. Is there something I can do while using scancodes?
First, the above code can be simplified to something like this:
if event is InputEventKey:
if event.scancode == KEY_F:
flashlight.visible = !flashlight.visible
However, that’ll have the same problem as your original code. That is, it’ll continue to toggle the light on/off as that code will fire as long as the key is pressed…
Is there a reason you’re trying to do this via a scancode? Why not just define an input action for your flashlight and then use something more standard, like:
if Input.is_action_just_pressed("flashlight_toggle"):
flashlight.visible = !flashlight.visible
HI, the reason for using scancode is that when I migrate projects I have to define the input actions all over again therefore I try to use it as little as possible. I was just wondering if there was a way but it seems there is none. Thanks a lot for your answer! Also your simplification is very welcomed.
dango1 | 2022-09-22 09:15
The input actions are stored in project.godot, so you can copy and paste them from one project to another.