+1 vote

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?

Godot version 3.4.2
in Engine by (13 points)

2 Answers

0 votes

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.

by (7,530 points)
0 votes

I don't know if it makes a difference if you use the Input singleton directly? That is

if Input.isactionpressed("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.iskeypressed(KEY_SHIFT):

and that returns true every frame.

One other thing you could try is setting a latch variable, like:

If Input.isactionjustpressed("multibuild"):
multibuildlatch = true
If Input.isactionjustreleased("multibuild"):
multibuildlatch=false

by (20 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.