How to find out whether its a mouse click or a mouse hold for duration

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Agentfox

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

:bust_in_silhouette: Reply From: Magso

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

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

One of those comparisions should be <= or >=

nosklo | 2019-04-18 01:23

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!

Agentfox | 2019-04-17 21:36

You’re right, thanks :slight_smile:

Magso | 2019-04-18 13:11