How to use an XBOX controller in BGE without Joystick Sensors

With 2.66 we can now use joysticks in the game engine without having to use any joystick sensors. I’ve attached a .blend file with a simple guide on how to script an xbox controller all in python. Make sure you have an xbox controller connected to your computer and open the system console. As you give controller input, you’ll see the console telling you what buttons you’ve pushed.

Attachments

xbox guide.blend (459 KB)

After checking the script above with ubuntu and mac, I realized that the xbox controller works differently on different operating systems. To get the controller to work the same way for all three, I made a script that checks what os you’re using and adjusts the xbox input accordingly. Here’s an example of a camera setup that works with an xbox controller on windows, linux, and mac. Take a look at the script called ‘gamepad’ to see exactly how this is done.

~doakey3

Attachments

character movement v3.zip (81.3 KB)

Thanks! Awesome that it is cross-platform

Not working

Thank you!
I begin to learn BGE and I was looking how to do that, working perfecly.

I keep getting "
Python scrip error - object ‘Cube’ , controller ‘Python’:
Traceback (most recent call last):
File “D_pad control”, line 10, in <module>
IndexError: list index out of range
"
Line 10 is “if xbox.hatValues[0] == 1:”
please help
I’m using 2.74 win7 64bit

Thanks a lot, this will be very helpful :slight_smile:

i dont know why but i cant see the code