0 votes

I need to use _input, but I also need a mouse action that behaves like a key, in the sense that while pressed it calls _input continuously. It seems impossible. Any suggestions?

in Engine by (1,120 points)

1 Answer

0 votes

You could create a flag that is set to true on the mouse pressed action, and false on the mouse released action, and then use _process() or some other technique to continuously fire off whatever you need to do.

by (524 points)

I would hardly be using _input if I did this. No, there's a reason why to use _input instead of _process and doing this gimmick is the same as using only _process

There is no way to check whether a mouse button is pressed other than periodically polling it, or keeping track of its state externally. The mouse just doesn't fire input events the same way keys do. Keys only repeatedly fire input events because that's the behaviour of a key that is held down - after a short period of the key being held the OS starts firing off more key presses which Godot detects. You can test this yourself.

Looks like it's either this gimmick or you're using only _process().

I setup a on_mouse_pressed(just_begun, released) signal and on the firearm a timer with the corresponding fire rate, which would call a function as long as mouse was pressed. Like this:

func _ready():
    Player.connect("on_mouse_pressed", self, "attack")
    Timer.connect("timeout", self, "attack", [false, false])

func attack(begun, released):
    if released:


This allows me to achieve any fire rate, i.e 120, without using the fps depending _process or the limited at 60 _physics_process.

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.