0 votes

I created a small script for move an Area2d on a grid, I want that the player taps the direction they want to move. If I control it at the keyboard it works flawlessly but for some reason, on the gamepad it execute two times I have no idea why:

const TILE_SIZE = 64

func _input(event): 
    if Input.is_action_just_pressed("ui_up"):
        move_cursor(  0 , -1 )
    elif Input.is_action_just_pressed("ui_down"):
        move_cursor(  0 ,  1 )
    elif Input.is_action_just_pressed("ui_left"):
        move_cursor( -1 ,  0 )
    elif Input.is_action_just_pressed("ui_right"):
        move_cursor(  1 ,  0 )

func move_cursor(x , y):
    cursor.position += Vector2(x , y) * TILE_SIZE
    cursor.pos += Vector2(x , y)

So I tried:

if Input.is_action_pressed("ui_up") and not event.is_echo():

and (I don't think that make difference):

if Input.is_action_just_pressed("ui_up") and not event.is_echo():

and:

if Input.is_action_just_pressed("ui_up") and event.is_pressed():

In every scenario the keyboard works well, I didn't changed anything on the input map as it just a prototype, ui_up for example is up on the keyboard and d-pad up.

I'm on linux, using a X360 gamepad

Maybe I should create a Issue on their github or maybe on SDL?

Godot version 3.2.3
in Engine by (105 points)
edited by

For future reference, this was cross-posted to GitHub: https://github.com/godotengine/godot/issues/45443

1 Answer

0 votes

you might be calling the function twice perhaps also we need to see the whole script to better help you out, and no I'm no export. also, have you tried adding a return?


   func _input(event): 
    if Input.is_action_just_pressed("ui_up"):
        move_cursor(  0 , -1 )
       return 
    elif Input.is_action_just_pressed("ui_down"):
        move_cursor(  0 ,  1 )
        return 
    elif Input.is_action_just_pressed("ui_left"):
        move_cursor( -1 ,  0 )
        return 
    elif Input.is_action_just_pressed("ui_right"):
        move_cursor(  1 ,  0 )
        return 
by (20 points)

There's nothing calling this function that are related to the gamepad, I created a new project only with this code and the bug remains. I really think that's a bug on the engine.

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.