If you want to add joystick control to your blender game!

Just a hint:

Install pygame (the python game libraries)

Here is the basic python script to add to your setup script:

import pygame
from pygame.locals import *

pygame.joystick.init()
GameLogic.Joystick = pygame.joystick.Joystick(0)

0 is your first connected joystick

Here is the basic python script to add to your character actuator:

if hasattr(GameLogic, ‘Joystick’):
x_ = GameLogic.Joystick.get_axis(0)
y_ = GameLogic.Joystick.get_axis(1)

pygame.event.pump()

I don’t own a joystick so I can’t test it. This is just a hint. I’m going to buy one soon.

A cleaner way could be to code a c library, maybe using SDL for portability, and make it into a python module. I’ll develop this as soon as I have a joystick.

Are you interested?

Hmm, wonder if your joystick in python will be different.

Someone already made one. Not exactly sure how well it functions with an actual game though.

Snailrose Joystick Demo
http://www.elysiun.com/forum/viewtopic.php?t=29550&highlight=joystick
AND
http://www.elysiun.com/forum/viewtopic.php?t=28826&highlight=joystick

Jason Lin

Ciacio = Snailrose? I’m thinking that all the times, because he knows a lot of python I think. :slight_smile: (yeah I got ya :P)

skz_ = snailrose:) would anyone like to see joystick support implemented in blender? no promises :frowning: but its worth a shot

Yeah if you can try it would be really nice. Maybe if you make it joystick supported, also try to make this linkable with driving steers on a pc, or made gameconsoles. Like the consoles of the playstation. :smiley:

Ok. But can someone with a joystick try the pygame trick? I can’t 'cause I don’t own one.

But Blender didn’t give me any error in the console and the get_count() function correctly reports 0: no joystick found.

Hey :slight_smile:
two things were left out

init pygame video,and init the pygame Joystick Object

here is the code that works for me


import pygame 
from pygame.locals import * 

pygame.init()

print pygame.joystick.get_count()

GameLogic.Joystick = pygame.joystick.Joystick(0) 

if hasattr(GameLogic, 'Joystick'): 
	GameLogic.Joystick.init()
	x_ = GameLogic.Joystick.get_axis(0) 
	y_ = GameLogic.Joystick.get_axis(1) 
	print x_,y_
	
pygame.event.pump() 

:-? I’m totally confused. Which one of you guys are snailrose?? Or none of you guys are snailrose? Why in the world would someone just use a new nick???

:frowning: goldentaiji runs off…

Are you supposed to run the script using an always sensor?

Jason Lin

SKZ_ is snailrose
forgot my pw :frowning:

yeah link it to an always sensor

SKZ_,
as I said I don’t own a joystick so I can’t test it, but:

  • try using just:
    pygame.joystick.init()

instead of

pygame.init()

beacuse you don’t need anything else than joystick . If this works, it is better. Otherwise pygame takes control of too many things. That’s the problem when you mix up different APIs.

I’ve noticed a long delay at start, and plenty of error messages from the console when using pygame.init().

But, even more important, don’t forget to split the initialization script from the part that does the query of joystick info.

Put the first part, the one that creates the GameLogic.Joystick var and initialize the joystick, on an always sensor that runs just once (pulse mode unchecked) and the rest on an always sensor that runs every few frames.

Let me know.

this is the reason I was using pygame.init()

so:


# error
try:
	pygame.joystick.init()
	#...
	pygame.event.pump() 
	
except pygame.error,e:
	print e
	

# works
try:
	pygame.init() # or pygame.display.init()
	pygame.joystick.init()
	#...
	pygame.event.pump() 
	
except pygame.error,e:
	print e

this is just for me anyway :frowning:

yeah forgot that :slight_smile:

So it works?

SKZ_ Lol, mail Timothy he can send you the password of the old user profile, it’s storred in the Elysiun database like veryone’s user profile. :smiley: