This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+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 (8,580 points)
+1 vote

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"):

by (22 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 Frequently asked questions and 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 [email protected] with your username.