Hello, I am trying to use a joystick for my experiment. However, when I use the joystick, the polygon cursor starts in the middle like intended, but when I try to move any direction the cursor just jumps to the farthest part of the screen instead of move across the space. I need to use the joystick so the cursor can touch different stimuli. Any advice is appreciated!
Could you please share the set up of your joystick component in the same way as you have with the polygon?
I can’t see anything wrong with the way that you’ve set this up, but could you please try the following:
- Downloading the latest version of PsychoPy here, as I can’t see anything immediately wrong here it could be due to a bug that is likely to be fixed in the latest release.
- If updating doesn’t solve your problem, could you please change the spatial units in the polygon settings from ‘from exp settings’ to norm and see if that makes a difference?
Hello, I have the latest version of pyschopy, and I have tried every option under from exp settings and it has not made a difference.
I wondered if it was the type of joysticks I was using? So I tried switching to joybuttons instead of joystick and had the same issue. Below are the gamepads I’ve been using.
I think what’s happening is that your joysticks, being d-pads, don’t output a screen position like with a Mouse component, they just tell you whether X is left, right, or stationary and whether Y is up, down or stationary. So
joystick.getY() will only ever be -1, 0 or 1.
To make the polygon move according to the joystick presses, you’d need to add a code component with something like this in the Each Frame tab:
x = (polygon.pos + joystick.getX()) * sensitivity y = (polygon.pos + joystick.getY()) * sensitivity polygon.pos = (x, y)
sensitivity is a value between 0 and 1, 0 meaning no movement at all, 1 meaning immediately jumping to the edge of the screen like it is now.
By adding the sensitivity = .1, it now moves .1 instead of 1 (to the edge). But it still only moves the one iteration and then returns to the center when no longer pressed. Whereas I need it to continue moving until the button is released, and once released it should remain in the last position. Is there a way to do this?
Thanks so much for your help.
What’s the exact code you used? The important thing is the code I shared is that the value from the joystick (adjusted for sensitivity) is added to the polygon’s position, rather than replacing the polygon’s position, so when you hold down the button it’s added each frame.
I changed the polygon/cursor position to:
Each frame code is:
And in begin experiment i have sensitivity = .1
Thanks for your help!
Oops, I think I see the problem… The brackets around
polygon.pos + joystick.getX() are wrong - sensitivity only needs to be applied to the adjustment, not the entire pos, so you can remove the brackets. My mistake!
As you’ve got
(x, y) in the position field in Builder you also don’t need the
polygon.pos = (x, y) line in the code component, but it isn’t doing any harm I think.
Yes! This worked! Thank you SO much for your help!