0
\$\begingroup\$

As in the question, really. I want to be able to detect if a gamepad has it's analogue input pushed as far as it can go in any direction.

Given x and y axis values in the range [-1, 1] (-1 being left and down respectively), how can I account for all of the angles between horizontal and vertical, as this means that I can't simply check if abs(axis) == 1.

As I'm unaware of how it might affect it, the engine I'm using is UE4, so any answer could take that into account.

\$\endgroup\$
3
  • \$\begingroup\$ I'm not sure if you'll be able to get an answer that will account for all the available devices: I've just tested my Logitech Attack3 (it's a joystick, not a gamepad), and the values will either have -1 or 1 in x or y when pushed at the limit. The range is sqare-ish, and not round-ish. My point is: maybe you'll need a pattern specific to each device you'll support. \$\endgroup\$
    – Vaillancourt
    Feb 2, 2017 at 13:52
  • \$\begingroup\$ @AlexandreVaillancourt Good point, hadn't thought about that. I'm using UE4, I don't know if that'll affect anything as far as standardising things goes. \$\endgroup\$
    – Yann
    Feb 2, 2017 at 14:00
  • 1
    \$\begingroup\$ If you're using an engine, chances are that it will abstract that for you. \$\endgroup\$
    – Vaillancourt
    Feb 2, 2017 at 14:04

1 Answer 1

1
\$\begingroup\$

Joysticks on gamepads are far from accurate. The best that you can do is designate a circular-ish region at the edge as fully pushed.

if(x*x + y*y > 0.9) 
\$\endgroup\$
3
  • \$\begingroup\$ The values should be absolute since -1 * -1 + -1*-1 = -4 \$\endgroup\$
    – Madmenyo
    Feb 2, 2017 at 15:26
  • 1
    \$\begingroup\$ @Madmenyo check your math again; (-1 * -1) == 1 which leads into (-1 * -1)+(-1 * -1) = 2 \$\endgroup\$ Feb 2, 2017 at 15:32
  • \$\begingroup\$ Err yeah ;), not sure how I managed to get -4 \$\endgroup\$
    – Madmenyo
    Feb 2, 2017 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .