Want to use a controller in your games?
First of all this script is for a single controller on the GD5 version only!
I use a Xbox controller.
I have created an external event that you must add to your scene so that you can use the controller.
Download the project below it contains the example “Platformer” with the support of the controller.
You can move the player with the left joystick and jump with RT.
The other buttons are not configured but you can already see how the events work!
A part is in Javascript, this part detects a controller and sends a signal if a button or a joystick is used.
The signal passes through scene variables that are created in the script directly.
(Tips : When you call a variable that does not exist GD will create this variable automatically)
This variable is then used in events, see “Axes” and “Buttons” groups.
If you have the possibility to test and make feedback on the script, javascript, or improvements do not hesitate to modify the script and send it all here!
This is now included with extension inside GDevelop 5, for know how find extension follow this link :
Thanks a lot, I was also trying to get this working
I have changed your example a little and mapped my PS4 controller and added two more buttons so we can also use the PS button and the Touch button on the PS4 controller
Did also tidy up a little, moved all debug text on a separated layer so we can hide it…etc GDevelop5_controller-input.zip (152 KB)
I did some testing with my Xbox controller and adding two buttons made it all buggy.
So I added conditions to know if the last two buttons exist.
And makes the debug texts more meaningful.
I corrected my nickname too:’)
For the addition of an extension I wouldn’t know how to do it alone like that, I prefer to do crafts with GD for the moment.
I’m looking at how the code works in the game engine but I’m not sure I’m contributing to it yet really great. GDevelop5_controller-input.zip (372 KB)
Sorry, it was not intentional, even now that you mentioned I saw a t there for a moment
Thanks, I didn’t thought of that. Wish we could use arrays in GD then we could just loop through all the buttons exists and store them in an array and people could use it with any controller with any number of buttons
When I run this example, I run into the following problem. When I hit a button on the controller, the correct action happens (jumping, moving, etc.), but it keeps doing that action and does not stop. For example, it repeatedly jumps or continues moving after I’ve let go of the button. From what I can gather, the variable is not being changed back to “false” when the button is released. The debugger text confirms this.
Also: after a first button press, no other buttons will work.
If it helps anybody, I found a solution that worked for me:
Put the requestAnimationFrame line outside of the gameLoop function (right after the closing } bracket). Somehow this allowed the function to repeat on each frame as desired. I also took out all of the code that did not pertain to buttons relevant to the specific controller I was coding for.
Sorry for up this topic, but I am having some trouble.
This extension only works with PS and Xbox joysticks? Because I can’t use with my generic controllers, and even with x360ce I cant emule to make work.
The extension is available in the extension list directly in GDevelop.
It supports 100% PS4 and Xbox360 and Xbox one controllers.
I cannot take into account all types of controllers. There are thousands of mapping for hundreds of different controllers.
You can connect your controller to this site (https://html5gamepad.com/) you can have the number that corresponds to the buttons and remap by modifying the extension.
Thanks! Maybe I am making some mistake, because my generic Joystick uses the same buttons than a PS (I am using a Twin USB Joystick). Just to be clear, the extension works even in testing inside GDevelop or need to ‘build/compile’ the project and play in a browser to make joystick work? Sorry I am noob at GDev and game development.
How could I remap extension?
I checked, my Twin USB Joystick axis are working in Gdev, but not the buttons…
I tried the website you write, when I press ‘cross’ he changes the value of B2 from 0 to 1.0, and in drivers ‘cross’ are showed as button 3, how can I make this work?
thanks!
Hi Bouh.
How do we remap the extension?
I have an old school NES USB controller and when I press the DPad left and right I see it moves axis #4 and #5. But I don’t know where to plonk those into the extension. Cheers
You can’t really without change ids related to buttons in the code of the extension.
I work on the extension for add more events.
And the next version of the extension require the next release of GD for working.
The new version of the gamepad extension 0.0.5 is ready!
If you have used this extension before, check all your parameters some of them have change of order !
Patch note:
New instruction and expressions:
Key is released.
Any key pressed.
Last pressed button (string)
Deadzone expression and action/condition have a new parameter
(The order of the parameters have changed, this break the compatibility on previous version.)
I use now lifecycle function for define the object used in the extension and catch the last key pressed and more stuff.
(This mean the extension is useable on b89 and recent.)
All functions have been reworked for working with the new object define in onFirstSceneLoaded.
Gamepad vibration work only on web export, not in preview, not in windows exports. Not working on electron in general (this was also the case in previous version).
Let me know if you have any issue with it. All feedbacks are welcome!
If you wan to know how install the extension see here how work extensions.
I just use the extension for first time with Xbox pad for windows and its working flawlessly . Great extension i will use it for every project from now on . Thank you man for making it . I appreciated this a lot. Excuse my English.