0 votes

Using If Input.isactionpressed() does not work for me for some reason. It results in just one input as opposed to a continuous one.

I want to know how I would be able to detect holding input.

in Engine by (56 points)

1 Answer

0 votes

As mentioned in this answer, it may be better to use the function Input.is_mouse_buttoned_pressed( mouse_number ) for detecting mouse clicks and when they're held down. In the _process() function:

func _process( some_change ):
    if Input.is_mouse_button_pressed( 1 ): # Left click
          # Perform some stuff.

In the _input() function:

var mouse_left_down: bool = false
func _input( event ):
    if event is InputEventMouseButton:
          if event.button_index == 1 and event.is_pressed():
                mouse_left_down = true
         elif event.button_index == 1 and not event.is_pressed():
                mouse_left_down = false
func _process( some_change ):
    if mouse_left_down:
                # Perform some stuff.

If you didn't know, when using Input.is_action_pressed( some_action ), it's usually used in the _process() function because it detects the input each frame.

Hope that helps.

by (2,462 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.