0 votes

For my project, I'm trying to make an RTS style game with the classic controls (CTRL selects multiple units, SHIFT adds multiple destinations, etc), and for the multiple destinations I'm using a dictionary that holds all the destinations and moves them all down by one when a destination is reached, but when you hold down SHIFT and click somewhere, it adds way too many destinations (I'll leave a link for what it's supposed to look like below), is there any way to make it so that it only adds a destination once every 3 seconds, or only on mouse click rather than mouse press?

Example (Age of Empires 3)

Here's a link to the project files
Project files

in Engine by (52 points)

1 Answer

+1 vote
Best answer

You can go to Project > Project Settings and add a mouse button to the input map. is_action_just_pressed() will work for a single click.

To add a destination every 3 seconds while holding the mouse button

var timeToaddDestination : float

func _process(delta):
    if timeToaddDestination => 3 && Input.is_mouse_button_pressed(BUTTON_LEFT):
        #add destination
        timeToaddDestination = 0
    elif timeToaddDestination < 3:
        timeToaddDestination += delta
by (3,219 points)
edited by

It works very well now! I was using is_action_pressed because I didn't know what the others did (I'm new to Godot). Now I guess I know!

Will lock down if, by luck, you end up with exactly 3.0 in timeToaddDestination.

One of those comparisions should be <= or >=

You're right, thanks :)

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.