Jump to content
  • Advertisement
Sign in to follow this  
Jaylach

Working with an XBox 360 controller thumbstick....

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. This question isn't game related, but it is related to programming an XBox 360 controller using XNA. I'm writing an application for work that uses a 360 controller for input. I can't go into much detail (NDA and such) about what we're actually doing with it, but I can share that the controller is used to move a selection in 8 directions. Those 8 directions correspond to angles on the joystick. For example, when the joystick is between the angles 111.5 and 68.5 I know we want to move UP. I have the code for that working just fine. When the joystick moves I'm able to figure out the angle and act accordingly. The problem I'm having is with the joystick sensitivity. If I make my first move close the boundary of a direction angle and then move the thumbstick slightly, the angle changes and thus your selection changes. This is bad as it makes the movement very sensitive and finicky. A good example would be if I'm on one selection and move the joystick UP, I get the selection that's UP - this is correct. However, if I move the thumbstick slightly I somethings I get that selection changed to what's UP-RIGHT. That's what I want to avoid. I need a way to make these selections "sticky" until I can be sure (through code) that you actually wanted to move off that selection. I'm currently checking the distance the joystick has moved, and if it's over a certain amount I take that input. However, doing it this way makes it very slow to move across the line of suggestions because the user will have to go back to zero and move it that specified amount again. A pretty good example of how I'd like the joystick to act is the XBox 360 onscreen keyboard you get when you send a message to someone. The selection is moved a letter but it's not finicky and it's not sensitive. If I then hold the thumbstick in the direction I originally pointed it, the selection moves from character to character in that direction. Any thoughts on how I can accomplish what I want? I'm sorry if I was not clear. I'll be happy to share more details with someone if they can shoot me a PM - I'm just trying to avoid divulging too many details on the public forum. Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Try using a dead zone around the center of the stick where you don't process its position unless it's outside of the dead zone.

Share this post


Link to post
Share on other sites
Quote:
Original post by RDragon1
Try using a dead zone around the center of the stick where you don't process its position unless it's outside of the dead zone.


Thanks for the reply :)

However, I have already tried this. I think the problem lies in my code. I'm recalculating every time the X or Y values of the joystick change. If one of the X or Y values change, and the angle changes, I fire off an event and do my processing.

The problem is if I move the joystick slightly out of the dead zone, an event fires. If I then continue to move the joystick, even just a little, and it was enough to change the angles, the selection on the screen changes. Considering the small values we're working with that very slight movement of the joystick is very easy to accomplish and causes the app to be very finicky, sensitive, and annoying.

Share this post


Link to post
Share on other sites
I'd suggest an extra smoothing step, also know as hysteresis.

When the joystick is outside of the middle deadzone, calculate your angle.

Figure out which octant you're in (which of your 8 directions) from the angle.

If you're in the same octant as last frame, nothing happens.

If you're in a different octant, check how close you are the border angle. If you're far enough past the border, switch your current state.

For example, if 0 is right, and 45 is up and right, normally you'd switch directions at 22.5. Checking against this value directly causes jitter back and forth. Instead, change directions when you're inside in the octant by a few degrees. We'll use 2.5 degrees as an example. To go from right to up+right, you'd need to reach an angle of 25. To go back to the right, you'd need to reach an angle of 20. A slight hand tremor won't move you 5 degrees, and won't flick from option to option.

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
I'd suggest an extra smoothing step, also know as hysteresis.

When the joystick is outside of the middle deadzone, calculate your angle.

Figure out which octant you're in (which of your 8 directions) from the angle.

If you're in the same octant as last frame, nothing happens.

If you're in a different octant, check how close you are the border angle. If you're far enough past the border, switch your current state.

For example, if 0 is right, and 45 is up and right, normally you'd switch directions at 22.5. Checking against this value directly causes jitter back and forth. Instead, change directions when you're inside in the octant by a few degrees. We'll use 2.5 degrees as an example. To go from right to up+right, you'd need to reach an angle of 25. To go back to the right, you'd need to reach an angle of 20. A slight hand tremor won't move you 5 degrees, and won't flick from option to option.


Thank you, this helped a lot.

However, it's still not perfect. When I start using the application at the speeds it'd designed for (very rapid movements) there still appear to be scenarios where the quadrant changes when I didn't mean for it to change.

For a little more information - we are creating a means for rapid text input using a joystick. Moving the thumbstick highlights a section of the keyboard (determined dynamically depending on current position). When I start to move the joystick (type) at speeds close to normal keyboard speeds the keyboard selection sometimes jumps. I will see it highlight one section on the screen but quickly jump to another due to the stick being moved.

Could this have to do with the speed I'm moving the joystick and/or have to do with me, the user, being inaccurate?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!