+1 vote

Hello there :3

Today I was working on SMG for player to shoot, and get some strange mouse behaviour.

My code is following:

var shoot_cool = 0.0;

...

func _input( event ): # fails on double click
    if( event.is_action_pressed( "shoot" ) ):
        shoot();

func _process( delta ):
    if( shoot_cool > 0 ):
        shoot_cool -= delta;
    else:
        if( Input.is_action_pressed( "shoot" ) ):
            shoot();

...

It works perfect for the keyboard input, and mostly fine for the mouse, except for when I do a double click, it shoot two times and stop shooting, even if the mouse button is still pressed.

So, did I missed something about double click handling or stuff?

in Engine by (25 points)

I'm having the same problem, except I'm working in 2D with _unhandled_input and a timer to space shots. I press twice quickly, it shoots twice and then Input.is_actualy_press("fire") on where fire is bound to LMB reads false. If I extend the time between shots and press twice farther apart, it works as expected.

1 Answer

0 votes

WHOAH!

Yeah this seems like a bug.

  ================================================
  Used your code, got the same buggy results in Godot 2.1.4.
  Used your code, and it worked correctly in Godot 3.0 alpha :)

  The following is for 2.1.4 :
  ================================================

Upon holding Left Mouse button (after double-click)
it is not returning true for
Input.is_action_pressed( "my_action" )

but after that, when you release Left Mouse it does return true for
event.is_action_released( "my_action" )
 

Compare to using this same code
holding single-click or holding space bar :
returns true for .is_action_pressed( "my_action" )
returns true for .is_action_released( "my_action" )
 

 ----------------------------------------------
Link to .gif on Imgur
Recap of Apple Horo's problem
enter image description here

 

 ----------------------------------------------
Link to .gif on Imgur
Here is a workaround.
An alternate way to script this in Godot 2.1.4
enter image description here

 

 ----------------------------------------------
Here's the code from the 2nd .gif
One way to work around this.

Requires Left Mouse Button added to Input Map for "shoot"

# For Godot 2.1.4
extends Node

func _ready():
    set_process_input(true)
    set_process(true)

var shoot_cooldown = 0.0;
var shoot_held_down = false

func _input( event ): # bug workaround
    if( event.is_action_pressed( "shoot" ) ):
        shoot_held_down = true
        shoot();
    if( event.is_action_released( "shoot" ) ):
        shoot_held_down = false

func _process( delta ):
    if( shoot_cooldown > 0 ):
        shoot_cooldown -= delta;
    else:
        if( Input.is_action_pressed( "shoot" ) 
            or shoot_held_down 
        ):
            shoot();

func shoot() :
    print( "lazr -- pew pew" )
    shoot_cooldown = 1

I added this to a Control node in the .gif,
but it'll work with any Node subclass

  -----------------------------------------------------------------------
  How to format .gd scripts you find online
  to fill in the TAB characters
  -----------------------------------------------------------------------
    1.   Select a tab character in Godot --> Ctrl+C
    2.   Ctrl+R --> replace 4 spaces with the Godot with Ctrl+V tab character
    3.   click "Replace All" a few times

by (120 points)

      ~ have a wonderful day ~

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.