Topic was automatically imported from the old Question2Answer platform.
Asked By
olli460
I have a basic game where the player can place towers on the map. Currently when they click the tower they have to select the tower again to place another one.
I want the player to be able to build multiple towers at once if they are holding the shift key but i can’t figure out how to check if they are holding it, It only seems to check it once
i assigned the shift key to the input keys under project setting and done this code to test it
if event.is_action_pressed("multi_build"):
print("Shift is pressed")
But i only get one message output, how can i check if they are holding it down?
I don’t know if it makes a difference if you use the Input singleton directly? That is
if Input.is_action_pressed(“multi_build”)
is how I would write your example. I haven’t used the shift key in the input mapper but I can poll it directly:
if Input.is_key_pressed(KEY_SHIFT):
and that returns true every frame.
One other thing you could try is setting a latch variable, like:
If Input.is_action_just_pressed(“multi_build”):
multi_build_latch = true
If Input.is_action_just_released(“multi_build”):
multi_build_latch=false
Either check every frame in a process function whether shift is pressed or have a boolean variable that is set to true when shift is pressed and false when it is released.