# How can I detect if a gamepad stick has been pushed to the limit?

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.

• 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. Feb 2, 2017 at 13:52
• @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.
– Yann
Feb 2, 2017 at 14:00
• If you're using an engine, chances are that it will abstract that for you. Feb 2, 2017 at 14:04

if(x*x + y*y > 0.9)

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