GameMaker: Studio

GameMaker: Studio

View Stats:
Gamepad?
I want my xbox one controller to make my player move with the left analog stick.
Here is the code i am using for the player

Step Event

/// Move The Player in the Step Event
var right_key = keyboard_check(vk_right)
var left_key = -keyboard_check(vk_left)
var up_key = keyboard_check(vk_up);
var down_key = keyboard_check(vk_down);

if (right_key) {
phy_position_x += spd;
sprite_index = spr_player_right;
image_speed = .2;
}

if (up_key) {
phy_position_y -= spd;
sprite_index = spr_player_up;
image_speed = .2;
}

if (left_key) {
phy_position_x -= spd;
sprite_index = spr_player_left;
image_speed = .2;
}

if (down_key) {
phy_position_y += spd;
sprite_index = spr_player_down;
image_speed = .2;
}
/// Stop Animating
if (!down_key and !right_key and !left_key and !up_key) {
image_speed = 0;
image_index = 0;
}


Create Event

///set fixed rotation
phy_fixed_rotation = true;
spd = 3.50;
image_speed = 4;

Last edited by Sappy Secretary; Dec 27, 2018 @ 11:04pm
< >
Showing 1-5 of 5 comments
The Winter Bud Dec 28, 2018 @ 2:34am 
Check out This video tutorial from Shaun Spawlding.
Zappy Dec 28, 2018 @ 2:38am 
You don't seem to have any gamepad input in place at all, so there's nothing gamepad-related here for us to really comment on. (If you don't know what to do, see the GamePad Input page of GameMaker: Studio's manual/documentation.)[docs.yoyogames.com]

Though, gamepad-unrelated, I will comment on the following:
Originally posted by Dan:
- var right_key = keyboard_check(vk_right)
var left_key = -keyboard_check(vk_left) -
These two lines (ignore the hyphens at the start/end) lack semi-colons ( ; ) at the end. All of the other lines that could use them have them, so you may want to add semi-colons at the end of those two lines to stay consistent with yourself.

Besides that, you're setting "left_key" to be 0 (zero) if the left arrow key is not held, but -1 (minus/negative one) if it's held. You may want to remove the minus sign in front of keyboard_check, so that it'll be 1 (positive one) if the left arrow key is held.
Daynar Dec 28, 2018 @ 3:52pm 
I just added gamepad support to a project, and you should also keep in mind that steam automatically remaps gamepads to emulate keyboard and mouse if it is open. So you will need to turn that off if you want to properly test gamepad input.
Sappy Secretary Dec 29, 2018 @ 12:37am 
Originally posted by The Winter Bud:
Check out This video tutorial from Shaun Spawlding.

Two Things: For Some Reason I Can Only Move Right And Trying To Go Left Does Nothing? And How Would I Do This So That My Rpg Player Can Move Up And Down?


/// Move The Player in the Step Event
var right_key = keyboard_check(vk_right) || (gamepad_axis_value(0,gp_axislh) > 0);
var left_key = -(keyboard_check(vk_left)|| (gamepad_axis_value(0,gp_axislh) < 0));
var up_key = keyboard_check(vk_up);
var down_key = keyboard_check(vk_down);
Zappy Dec 29, 2018 @ 2:00am 
Originally posted by Dan:
Two Things: For Some Reason I Can Only Move Right And Trying To Go Left Does Nothing? -
var left_key = -(keyboard_check(vk_left)|| (gamepad_axis_value(0,gp_axislh) < 0));
-
That's because that you're checking "if left_key", which executes the next thing if "left_key" is more than or equal to 0.5, while you're still setting "left_key" to be 0 (zero) when it should be 0 (zero) and -1 (minus/negative one) when it should be 1 (positive one).
< >
Showing 1-5 of 5 comments
Per page: 1530 50

Date Posted: Dec 27, 2018 @ 10:46pm
Posts: 5