Mapping Gamepad, adding not conventional gamepads to Defold

Hello everyone,

While developing a StepMania like game (but with the defold engine) Iā€™ve found a problem I have not been able to solve. The engine appears not to recognize my dancepad ā€œRedOctane USB Padā€, nor my ā€œUSB Joystickā€ gamepad. However, it perfectly recognizes my keyboard.

Iā€™ve searched through this forum and found out thereā€™s support for Xbox controllers, so I started digging into the builtins of the engine until I found the default.gamepads GAMEPAD file.
Iā€™ve been playing with it for a while trying to make any of my controllers work, but, even though windows recognizes them and I can use them to play other games, my defold game doesnā€™t seem to take any signal from them.

Any idea on the issue? I thought that just configuring the default.gamepads file was going to be enough, but it appears itā€™s not.

Thanks in advance!

1 Like

Wow, love the usage of non-conventional input! :smiley:

It should be possible to just add a new gamepad entry, as you said.

Copy the default.gamepads from builtins to your own project, then change the gamepads entry in your game.project to point to your new file:

But since the controller identifies as something not available in the current default.gamepads file, you will need to add an entry for it yourself. Thankfully we have a little tool for this, hold on and Iā€™ll upload it here, what platform are you running on?

1 Like

Hi sven! Thankyou very much for your quick answer.
Iā€™m on a windows laptop.

Iā€™ve already modified the default.gamepads file, and right now it looks like this:

driver
{
device: "RedOctane USB Pad"
platform: "windows"
dead_zone: 0.200
map { input: GAMEPAD_LPAD_LEFT type: GAMEPAD_TYPE_BUTTON index: 1 }
map { input: GAMEPAD_LPAD_RIGHT type: GAMEPAD_TYPE_BUTTON index: 4 }
map { input: GAMEPAD_LPAD_DOWN type: GAMEPAD_TYPE_BUTTON index: 2 }
map { input: GAMEPAD_LPAD_UP type: GAMEPAD_TYPE_BUTTON index: 3 }
map { input: GAMEPAD_RPAD_LEFT type: GAMEPAD_TYPE_BUTTON index: 5 }
map { input: GAMEPAD_RPAD_RIGHT type: GAMEPAD_TYPE_BUTTON index: 8 }
map { input: GAMEPAD_RPAD_DOWN type: GAMEPAD_TYPE_BUTTON index: 6 }
map { input: GAMEPAD_RPAD_UP type: GAMEPAD_TYPE_BUTTON index: 7 }
map { input: GAMEPAD_START type: GAMEPAD_TYPE_BUTTON index: 9 }
map { input: GAMEPAD_BACK type: GAMEPAD_TYPE_BUTTON index: 10 }
}
driver
{
device: "USB Joystick"
platform: "windows"
dead_zone: 0.200
map { input: GAMEPAD_LSTICK_CLICK type: GAMEPAD_TYPE_BUTTON index: 11 }
map { input: GAMEPAD_LSHOULDER type: GAMEPAD_TYPE_BUTTON index: 5 }
map { input: GAMEPAD_RSTICK_CLICK type: GAMEPAD_TYPE_BUTTON index: 12 }
map { input: GAMEPAD_RSHOULDER type: GAMEPAD_TYPE_BUTTON index: 6 }
map { input: GAMEPAD_RPAD_LEFT type: GAMEPAD_TYPE_BUTTON index: 4 }
map { input: GAMEPAD_RPAD_RIGHT type: GAMEPAD_TYPE_BUTTON index: 2 }
map { input: GAMEPAD_RPAD_DOWN type: GAMEPAD_TYPE_BUTTON index: 3 }
map { input: GAMEPAD_RPAD_UP type: GAMEPAD_TYPE_BUTTON index: 1 }
map { input: GAMEPAD_START type: GAMEPAD_TYPE_BUTTON index: 10 }
map { input: GAMEPAD_BACK type: GAMEPAD_TYPE_BUTTON index: 9 }
}

Iā€™m not quite sure if the modifications Iā€™ve made are on the right path actually.

1 Like

You are on the right track! But we have a tiny tool that can be run to generate the .gamepads file;

gdc.zip (782.8 KB)

Includes binaries for OSX, Windows and Linux. You should just run it from a terminal, like;

./gdc

And it will ask you to press different buttons on your connected controller, the output will be a new gamepads file with correct mappings.

Hope this helps!

10 Likes

I agree with Sven. I love that youā€™re using non-conventional input in your game! I also think we should post something about the gdc tool to the Defoldmine section on the forum and encourage users to share their gamepad mappings.

5 Likes

I really appreciate the help!

Iā€™m sure Iā€™m not using correctly the gdc program, because I get the following result:

but my gamepad is already usb plugged. I have also checked that windows recognises my device, so Iā€™m probably not using the correct command line to call the program.

Hopefully this will be the last doubt!

No that should be enough, looks like itā€™s not able to find the gamepad/joystick, strange. Could you try using a third part tool to verify itā€™s found and identifiable as a joystick? Try Joystick Tester from here: http://www.mcrenox.com.ar/downloads/

2 Likes

When I first tried the joystick tester it didnā€™t recognise the gamepad, but I activated an option at the Printers and Devices pannel of windows and the joystick tester started to work:


However, and unfortunately, the gdc program still refuses to detect the joystick.

Also worth noting that the gdc tool expects you to press and hold a button for a second. If you just quickly tap the button, it wonā€™t recognise the input.
Took me about 10 minutes to figure out why the tool didnā€™t work for me, heh.

7 Likes

Thanks for your answer @sergey.lerg .
I am still stucked with the problem though, because the moment I execute gdc.exe, it just says:

FATAL:HID: could not set glfw char callback.
No connected gamepads, bye!

It says so even if I have been holding a button from the gamepad for a while and then, without unholding the button, I execute gdc.exe.
I have tried again the gamepad with Joystick Tester as @sven suggested some time ago, and it works perfectly - it also works with different emulators.

So I still think there is something about how Defold or the gdc tool are build that make them not recognize my gamepads.

Have you tried a conventional game pad, like an Xbox controller? Did that work? Is it more than the controller you mentioned in your original post that doesnā€™t work?

Hi, I had some problems on my mac with gamepad, too.
Mac OS siera, defold 2 pre-release
I tried gdc and it told that everything is ok and device will be added - but I still donā€™t see it in default or custom fileā€¦ and game on start writes that
WARNING:INPUT: No gamepad map found for gamepad 0 (Wireless 360 Controller), it will not be used.
INFO:DLIB: SSDP: Started on address 192.168.1.52
WARNING:INPUT: No gamepad map registered for gamepad 0, not used.

only a hand modification of default.gamepads helped - just copy one section and add the same with name device: "Wireless 360 Controller"
butā€¦ buttons works not the same as expected :frowning:
is there simplier way or convert generated with gdc to a needed format?

Gdc should generate a file or section of a file (canā€™t remember which and I canā€™t test now) that you can include in a copy of the default gamepads file. It will not automatically add anything.

where this file can be find?
please, answer when it will be possible
I donā€™t know fileā€™s name and have no idea where to find it

Based on @svenā€™s previous post the gdc tool should spit out a gamepads file with correct mappings that you can merge with a copy of the master gamepads file.

the problem is - I had no new file or just canā€™t find it

Oh, hmm, @sven any idea?

for now my gamepad ā€œWireless 360 Controllerā€ works in Defold on macos because I copied area for microsoft xbox one contoller and change its name and set needed platformā€¦ and now everything works good. but I want to add one more controller (a popular for mobile I guess) 8bitdo zero. so I really need to get where file generated by gdc can be found

I ran the gdc tool on OSX and the tool writes a default.gamepads file in the same folder. If youā€™re trying this on Windows I think you need to ensure that the tool is run from a location where your user has write access (or perhaps run as administrator or something like that).