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).