• 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!

GameMaker Trying to get gamepad working

Geoff Jones

Member
Hello!

I'm new to configuring gamepads...

So the gamepad im trying to get to work in a small test project is this one:


It works in windows, I understand that it will be detected as device 4 in game maker, which it does.
but setting movements controls to the up button (gamepad_button_check(4, gp_padu)) doesn't seem to register. It works fine with my Logitech controller. I can confirm the gamepad does work perfectly on other systems.

Any idea what I need to do?
 

Phil Strahl

Member
Have you tried reading all the buttons on it? With strange aftermarket controllers you can never be sure how the buttons are mapped in the hardware. So button1 might be down, or gp_padu maps to X, etc. The only things you can do about this is writing code to automatically remap the buttons depending on the string the gamepad return as name (quick and dirty but limited to the pads you have at hand) or, better, to make it possible for players to remap buttons by themselves (lots of work).
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, gamepads... You should first of all create a persistent controller object to detect gamepad connection and disconnection, and then in the Async System event check the pads. This controller should be the FIRST thing created in the game, so that pads are registered immendiately, and you should do it in a loop and assign the pad index(s) to a global variable or array so that you can check them in any other instance later. See this article here:
https://www.yoyogames.com/blog/75/how-to-setup-and-use-gamepads

It's for GM:S 1.4, but it's perfectly valid for GMS2 as well. The GMS2 start page > Tutorials section also has tutorials in GML and DnD for setting up a gamepad, which I suggest you do.
 

Geoff Jones

Member
Thanks for the responses, everyone.

I went throug thge tutorial, and modified it a bit so that every button is showing.
upload_2019-6-19_19-51-26.png

All buttons work, except for the direction pads. This controller doesn't have an analogue stick.
When I press the left or right direction pads, all values for gp_axis change to either 1 or -1, when I press up or down, no values change for anything.
So the directions pads seem to be mapped as an analogue stick. Is there still a way to use this controller? I can see how I would get the left and right pads to work, but not up or down.
 
D

diester

Guest
If it can help for the same type of gamepad I used this in step :

var h_move = gamepad_axis_value (5, gp_axislh);
var v_move = gamepad_axis_value(5, gp_axislv);

if ((h_move != 0) || (v_move != 0))
{
x += h_move * 4;
y += v_move * 4;
}

For a controller with the digital stick :

var h_move = gamepad_button_check(4, gp_padr) - gamepad_button_check(4, gp_padl);
var v_move = gamepad_button_check(4, gp_padd) - gamepad_button_check(4, gp_padu);

if ((h_move != 0) || (v_move != 0))
{
x += h_move * 4;
y += v_move * 4;
}

it works for me
 
Top