gamemaker_easy_twin_stick.txt

My easy twin-stick shooter movement code is available below for both gamepads & mouse/keyboard, thanks for watching!

Paste into player object’s create event:

direction = image_angle;

gamepad_set_axis_deadzone(0,0.2);

var player_speed = 7; //adjust speed here

Paste into player object’s step event:

//SET DEADZONE LIMIT

var deadzone_limit = 0.2;

//GAMEPAD L-STICK MOVEMENT

if gamepad_axis_value(0,gp_axislv) >= -deadzone_limit && gamepad_axis_value(0,gp_axislv) <= deadzone_limit 

&& gamepad_axis_value(0,gp_axislh) >= -deadzone_limit && gamepad_axis_value(0,gp_axislh) <= deadzone_limit

{

image_angle = direction;

speed = 0;

}

else

{

var hlaxis = gamepad_axis_value(0, gp_axislh);

var vlaxis = gamepad_axis_value(0, gp_axislv);

direction = point_direction(0, 0, hlaxis, vlaxis);

speed = point_distance(0 ,0, hlaxis, vlaxis) * player_speed;

}

//GAMEPAD R-STICK TARGETING

if gamepad_axis_value(0,gp_axisrv) >= -deadzone_limit && gamepad_axis_value(0,gp_axisrv) <= deadzone_limit 

&& gamepad_axis_value(0,gp_axisrh) >= -deadzone_limit && gamepad_axis_value(0,gp_axisrh) <= deadzone_limit

{

image_angle = direction;

}

else

{

var hraxis = gamepad_axis_value(0, gp_axisrh);

var vraxis = gamepad_axis_value(0, gp_axisrv);

image_angle = point_direction(0, 0, hraxis, vraxis);

}

Code for keyboard movement & mouse targeting below. WASD keys move, mouse is used for targeting.

Paste into player object’s create event:

direction = image_angle;

Var player_speed = 7; //adjust speed here

Paste into player object’s step event:

//MATCH PLAYER DIRECTION TO WHERE MOUSE IS

image_angle = point_direction(x,y,mouse_x,mouse_y)

//KEYBOARD CONTROL

//6 AXIS MOVEMENT

//RIGHT & DOWN

if keyboard_check(ord('S')) && keyboard_check(ord('D'))

{

direction = -45;

speed = player_speed

}

//LEFT & DOWN

else if keyboard_check(ord('S')) && keyboard_check(ord('A'))

{

direction = -130;

speed = player_speed

}

//RIGHT & UP

else if keyboard_check(ord('W')) && keyboard_check(ord('D'))

{

direction = 45;

speed = player_speed

}

//LEFT & UP

else if keyboard_check(ord('W')) && keyboard_check(ord('A'))

{

direction = 135;

speed = player_speed

}

//4 MAIN DIRECTIONS

//RIGHT MOVE

else if keyboard_check(ord('D'))

{

direction = 0;

speed = player_speed

}

//LEFT MOVE

else if keyboard_check(ord('A'))

{

direction = 180;

speed = player_speed

}

//DOWN MOVE

else if keyboard_check(ord('S'))

{

direction = -90;

speed = player_speed

}

//UP MOVE

else if keyboard_check(ord('W'))

{

direction = 90;

speed = player_speed

}

else

{

speed = 0;

}

Leave a Comment

Your email address will not be published.