Web Editor release candidate, HTML5 gamepads and more!
By: Fabio Alessandrelli Feb 04, 2021
Howdy Godotters! Time for another brief update on the HTML5 export for Godot.
First of all, the Web Editor reached release candidate state, and now has a dedicated address where you can also browse previous releases. There are still few issues (#44754, 44755) we are ironing out, but it should be gold by the end of the month.
During December, realizing how poor gamepad support was on the web, I spent some time fiddling around with the HTML5 Gamepad API trying to improve the situation. The standard itself is sadly incomplete (see w3c/gamepad#7 and w3c/gamepad#9) making remapping of controllers hard guesswork.
Important: When talking about mapping in this post, I'm not referring to your game action mapping, but making sure that pressing the button labelled "
A" in your Xbox controller is correctly recognized by Godot as
JOY_SONY_X, i.e. the button labelled "
X" in your DualShock controller).
First of all, gamepads cannot be detected on the Web until a button is pressed on them. Then, the controller is either remapped to a
standard mapping by the browser, or its raw inputs are used.
Normally, Godot and other software would remap raw inputs using a database of known controllers and detecting them based on information passed by the operating system like the device vendor and product ID, and its "connection type" (bus information). As mentioned above, those information are not always available using the Web Gamepad API, but can sometimes be obtained via guesswork.
The main issues are:
gamepad.iddoes not always contain vendor and product ID, additionally its format differs across browsers. Bus informations are not available.
- The same product/vendor IDs results in different raw inputs on different operating systems.
[browsers,OS,gamepad]combinations produce inputs or mappings outside of the specification (e.g. axis values outside the
standardbut not actually following the standard specification).
But nevertheless, we can do something to better our gamepad support on the Web for many devices. To do this, we need to guess the operating system the browser is running on, then try to read informations about vendor and product from the
gamepad.id string, and finally provide mapping informations for that gamepad on that OS. Of course, none of this is necessary in the (rare for now) cases where the browser already remaps the gamepad following the standard.
A simple UI is being added to the joypads demo that allows to easily generate a controller mapping for a new device. That UI was used to generate mapping for all controllers I could come across on Linux/Windows/macOS after bothering friends and family during the holidays. This includes most (all?) official Xbox controlers (wired), and two compatibles I had lying around.
Please note: If the controller is detected as
standard but it's not correctly mapped or if moving any axis shows a value outside the range
[-1,1], it's probably a browser bug and we can't do much about it (probably worth reporting to the browser issue tracker).