I know that using python to gain analog joystick control has been covered in the forum before, but I thought I’d post this anyway in case anyone could use it (and for those of you who don’t know how to use the search :p). Here’s an example blend with the python script in it. I made it with 2.42 RC2, but it should work in 2.41 if you just change the physics to Sumo. Analog joystick test blend with Calibration
Controls for the game are left and right on joystick to move, button 0 to jump.
I tried this on a friend’s computer, and his joystick has different min/max axis values than mine. Therefore, I have implemented a calibration system to make performance consistent regardless of which joystick you use. Try it out and let me know how it works for you!
bigkahuna: No, its pretty simple. I mainly focused on the first two axes. I use a Gravis Gamepad because I like classic 2-4 button Nintendo-style games, so I only have two axes and four buttons to work with :). Besides, a lot of the scripting for an actual game would depend on what you wanted the player to do, so it kinda didn’t make sense to me to write all of it. The point of the exercise (for me) was to overcome the digital “on/off” type of support for the axes and provide real analog support. I accomplished that, and I thought I’d post it in case anyone could learn from it. (It would have been quicker if I would have just searched the forum first. I wasted so much time messing around with Pygame before I thought to look up the properties on Blender’s joystick sensor…)
Jacco: Were you responding to bigkahuna, or were you telling me that it wasn’t working for you?
I updated the joy2.blend file. It now includes a calibration system to make performance consistent regardless of which type of joystick you use. Please check the topmost post for the new download. Enjoy!
Herman, I uploaded the file again and tested it from the site. It runs fine on my Blender, so let me know if you’re still having errors. I’m using 2.42a (which probably doesn’t have anything to do with it).
Like I said, it works very well, but the joystick sensors stop working after an overlay scene is removed (not added). [I would upload a blend file if I could, but you can test it easily by adding an overlay in the Game scene, and remove it again after a few seconds].
Is there something special I must do or a possible workaround? Some tests of my own makes it look like a blender problem, not anything you have done in your scripts.
From what you’re describing, it does sound like a Blender problem. I’ll test it tonight when I get a chance and see if I can come up with anything. Perhaps a joystick overlay scene that sends values to global variables would work. That way you could restart the joystick scene every time you remove another scene. I’ll try it, but I need to find where that global variables tutorial was… somebody had one on their site. Their avatar is a Blender logo on white background (unless they changed it since then), but I can’t remember their screenname.
You can use the GameLogic module for global variables.
#ascript.py somewhere in your game
import GameLogic
GameLogic.aVar = someVal
#anotherscript.py elsewhere in your game
import GameLogic
if GameLogic.aVar == aVal:
do something
else:
do something else