• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows How to check left, right, and up on analogue stick on gamepad?

I

iNCEPTIONAL

Guest
I'm not sure how to check the left, right, and up directions on the left analogue stick when trying to use gamepad commands?

The left and right directions seem to combined into a single horizontal axis (gp_axislh), and the same with up and down (gp_axislv), which is different to the d-pad where you can specifically select the likes of left and right separately with gp_padl and gp_padr, and up with gp_padu.

This is the code I'm using:

Code:
left                = (keyboard_check(ord('A')) or (keyboard_check(vk_left)) or (gamepad_button_check(0, gp_padl)) or (gamepad_axis_value(0, gp_axislh)))
right               = (keyboard_check(ord('D')) or (keyboard_check(vk_right)) or (gamepad_button_check(0, gp_padr)) or (gamepad_axis_value(0, gp_axislh)))
forward             = (keyboard_check(ord('W')) or (keyboard_check(vk_up)) or (gamepad_button_check(0, gp_padu)) or (gamepad_axis_value(0, gp_axislv)))
backward            = (keyboard_check(ord('S')) or (keyboard_check(vk_down)) or (gamepad_button_check(0, gp_padd)) or (gamepad_axis_value(0, gp_axislv)))
But as you can see, the left and right commands use the same axis at the end, gp_axislh, because there doesn't seem to be any other option to choose for left and right separately.
 

GMWolf

aka fel666
gamepad_axis_value(0, gp_axislh) will return a value between -1 and 1;
-1 is stick to the left, 0 is in the center and 1 is to the right. it can also return any value in between.
one trick is to check if they are greater than a threshold.
so left:
gamepad_axis_value(0, gp_axislh) < -0.5
and right:
gamepad_axis_value(0, gp_axislh) > 0.5

you can also check out my tutorial on uusing gamepads, where i uase a different setup:
Youtube link
 
I

iNCEPTIONAL

Guest
gamepad_axis_value(0, gp_axislh) will return a value between -1 and 1;
-1 is stick to the left, 0 is in the center and 1 is to the right. it can also return any value in between.
one trick is to check if they are greater than a threshold.
so left:
gamepad_axis_value(0, gp_axislh) < -0.5
and right:
gamepad_axis_value(0, gp_axislh) > 0.5

you can also check out my tutorial on uusing gamepads, where i uase a different setup:
Youtube link
Cool, that did the trick.

Thanks :-D
 
Top