Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with Y-Axis on gamepad  (Read 2350 times)

0 Members and 1 Guest are viewing this topic.

user1234

  • Newbie
  • *
  • Posts: 1
    • View Profile
Problem with Y-Axis on gamepad
« on: July 25, 2014, 07:25:00 am »
Hi, I have a Logitech gamepad. My application recognizes there's a controller of id 0. When I start my Pong game, the left pad moves upward for some odd reason. However, I'm not pressing up on the gamepad's Y axis when this happens.

While debugging, I get this value for joy.y_pos = "-0.0015259022". This is without pressing anything on the gamepad. I would expect the value to be 0. My gamepad works for other games, so I'm not sure why this is causing different behavior.

Moving the pad up/down on the Y-axis has no effect, as the pad just keeps wanting to move upward. The controller was calibrated.

I'm using SFML 2.1 on Win32(Windows 7). Controller: Logitech 940-000110 Gamepad F310. Are there any known reasons to this problem? Thanks.

Code: [Select]
joy.y_pos = sfJoystick_getAxisPosition(JOYSTICK_ID_0, sfJoystickY);
if (joy.y_pos < 0) {
joy.blnDown = FALSE;
joy.blnUp = TRUE;
}
else if (joy.y_pos  > 0) {
joy.blnDown = TRUE;
joy.blnUp = FALSE;
}

« Last Edit: July 25, 2014, 07:38:16 am by user1234 »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Problem with Y-Axis on gamepad
« Reply #1 on: July 25, 2014, 08:30:44 pm »
This seems normal to me.  Peripherals are never going to be so flawless that the default state is exactly (0,0) on all machines.  And most of the time you should be using joystick events to control your game logic so this won't be an issue anyway.  If you really do need its position for some reason then you'll have to write some calibration logic to compensate for these real-world inaccuracies (you know how every video game asks you to calibrate the brightness at the beginning? it's kinda like that).

Chaore

  • Newbie
  • *
  • Posts: 41
    • View Profile
    • Email
Re: Problem with Y-Axis on gamepad
« Reply #2 on: July 25, 2014, 09:27:42 pm »
My gamepad works for other games, so I'm not sure why this is causing different behavior.


Yeah, other games don't test joystick larger than or smaller than 0 like you did in your code.  ;)

Maybe something like this will work as you expected?  :)
 
Code: [Select]
joy.y_pos = sfJoystick_getAxisPosition(JOYSTICK_ID_0, sfJoystickY);
myObject.y+=joy.y_pos*0.2f;

Did you ever play Nintendo 64?  With the time controllers joystick began to be very soft.  So you can't expect to always have it to 0.  ;)
« Last Edit: July 25, 2014, 09:31:08 pm by Chaore »