GameMaker How to have right stick override left stick?

S

skadoodlefap

Guest
Hey everyone, I'm currently working on a small project in the GMS 2 trial version and I've run into a problem. I am trying to make my player aim an object around him while he's moving with the left stick on the controller, but you can also switch to the left stick for precise aiming. The thing is, I want to be able to use the left stick while moving the right stick but the right stick seems to have priority in deciding the aim. Here is my code:


var controllerhr = gamepad_axis_value(0,gp_axisrh)
var controllervr = gamepad_axis_value(0,gp_axisrv)
var controllerh = gamepad_axis_value(0,gp_axislh)
var controllerv = gamepad_axis_value(0,gp_axislv)

if oPlayer.controller == 1{
if abs(controllerhr) > 0.2 or abs(controllervr) > 0.2{
controllerangle = point_direction(0,0,controllerhr,controllervr)
}
if gamepad_button_check_pressed(0,gp_face3) or gamepad_button_check_pressed(0,gp_shoulderrb) and firingdelay < 0 and ammo > 0{
firingdelay = 4;
ammo -= 1;
oPlayer.hsp-= lengthdir_x(playerrecoil,image_angle);
oPlayer.vsp-= lengthdir_y(playerrecoil,image_angle);
with instance_create_layer(x,y,"Kunai",oKunai){
speed = 15;
direction = other.image_angle;
image_angle = direction;
}
image_angle = controllerangle
}
}



if oPlayer.controller==1 and inuse==0{
if abs(controllerh) > 0.2 or abs(controllerv) > 0.2{
controllerangle = point_direction(0,0,controllerh,controllerv)
}
image_angle = controllerangle
}
 

Kahrabaa

Member
I don't know if I understand correctly, but I think if a change overrides a variable it is because of the order in which you wrote the change to the variable. Code is read from top to bottom, so what was the last change before going to the next frame?
If this is the problem then I would use two separate variables for each stick and then decide in the end to choose one over the other.

Random example:
Code:
if( keyboard_check( vk_left ) ){
testvariable = 1;
}
if( keyboard_check( vk_right ) ){
testvariable = 2;
}
Now if you hold both left and right down. Testvariable would end up being 2 because of the order.
 

Relic

Member
Also a little confused, but currently your code:
  1. sets controllerangle based on the right stick IF right stick is not in neutral position
  2. fires oKunai if a gp_face3 or gp_shoulderrb is pressed, in direction of player image_angle (not set yet this step, so last step's image_angle)
  3. sets player image_angle to controlleangle
  4. changes controllerangle IF left stick is not in neutral position
  5. sets player image_angle to controlleangle

Try play out the steps in your head - is this behaviour desired?
 

FrostyCat

Redemption Seeker
Try adding the left and right stick inputs together and acting only on the net result. Case-by-case handling is almost always inappropriate when two non-mutually-exclusive input sources cross-interact. It's the same problem with how some rookies struggle with conflict between the left and right arrow keys.
 
Top