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

Ladders and Gamepad input

B

bobula13

Guest
Hey all,

I've written a script for ladders in my game and whenever I use the keyboard the code works just fine. For some reason when I plug in a wired 360 controller the character automatically climbs up the ladder when near it OR if I press any movement on the left joystick it automatically spawns at the middle point of the ladder.

Is this a known issue of any kind?
 
B

bobula13

Guest
Here's the code in the script I have written:

///scr_ladder
scr_get_input();
hspd = 0
vspd = 4 *(down_key - up_key);
x = (instance_nearest(x,y,obj_ladder).x+16);
if(jump_key) || (!place_meeting(x,y,obj_ladder))
{
hspd = 0
vspd = 0
state = scr_move_state
}
 
B

bobula13

Guest
Yeah, it does the job just fine when using only the keyboard for input. But when I plug in a controller for some reason the character just starts climbing up the ladder on its own.
 

obscene

Member
Well you don't explain how your gamepad controls work. If your up and down are on an axis then probably it never reaches a true 0. Look up gamepad_set_threshold() I think that's it at least.
 
B

bobula13

Guest
I've set the threshold for the controller at .5:
//Gamepad controls
var gp_id = 0;//represents the gamepad we have plugged in
var thresh = .5;//this is a threshold so that the input doesn't return a value in tiny increments
if(gamepad_is_connected(gp_id))
{
right_key = gamepad_axis_value(gp_id, gp_axislh) > thresh;
left_key = gamepad_axis_value(gp_id, gp_axislh) < -thresh;
down_key = gamepad_axis_value(gp_id, gp_axislv) > thresh;
up_key = gamepad_axis_value(gp_id, gp_axislv) < thresh;
jump_key = gamepad_button_check_pressed(gp_id, gp_face1);
jump_release = gamepad_button_check_released(gp_id, gp_face1);
attack_key = gamepad_button_check_pressed(gp_id, gp_face3);
}
 
Top