GMS 2 Joystick cardinal directions sticking

Roastedzerg

Member
I'm trying to make the joystick movement and aiming in my game butter smooth so the slightest tweak in the joystick will slightly turn the player in a direction incrementally. However, most of the joystick stuff i could find for game maker is the same and has a problem with having a sort of deadzone with the cardinal directions (up, down, left, right). And i dont mean incremental speed adjustment like walking to jogging, but adjustment to movement or aiming direction.

Example: if i hold left on the joystick, then slightly move the joystick upwards, he will ignore the slight adjustment, moving straight left, until the joystick leaves what feels like some kind of deadzone above and below perfect left.

How do i make a more accurate joystick adjustment?

Heres what ive got so far for the aiming:

GML:
//Gamepad Movement
if(!is_dodging){scr_move_axis(xaxis,yaxis,gamepad_get_axis_deadzone(gamepad_device),x_speed_max);}

//scr_move_axis
xaxis=argument0
yaxis=argument1
threshold=argument2
magnitude=point_distance(0,0,xaxis,yaxis)
spd=argument3
if(can_move)
{
    if(!is_dodging&&hor_move==0&&vert_move==0)
    {
        if(magnitude>=threshold)
        {
            x_speed+=xaxis*spd;
            y_speed+=yaxis*spd;
        }
    }
}

//Joystick aiming
if(xaxis_aim!=0||yaxis_aim!=0)
{
    use_mouse=false;
    var pdir=point_direction(0,0,xaxis_aim,yaxis_aim);
    var dif=angle_difference(pdir,aim_angle);
    aim_angle+=median(-20,dif,20);
}
 
Last edited:

O.Stogden

Member
I use this code for moving a cursor about on-screen, not sure if it's what you want:

Code:
if (gamepad_axis_value(global.p1gamepad, gp_axislh) > 0.25 || gamepad_axis_value(global.p1gamepad, gp_axislh) < -0.25 || gamepad_axis_value(global.p1gamepad, gp_axislv) > 0.25 || gamepad_axis_value(global.p1gamepad, gp_axislv) < -0.25)
{
x+=10*gamepad_axis_value(global.p1gamepad,gp_axislh)
y+=10*gamepad_axis_value(global.p1gamepad,gp_axislv)
}
 

Roastedzerg

Member
Im afraid that will give me the same issue. The joystick movement and aiming i'm using work just fine, but for some reason it would seem game maker has a sort of soft-lock for the joystick's cardinal directions.
 

O.Stogden

Member
You mean a deadzone? You can change that with gamepad_set_axis_deadzone.

Be aware that it might cause issues if you use your own deadzone code, as it will change the value returned by the gamepad_axis functions.

I'd keep an eye on what xaxis and yaxis are, as the deadzone code will be lowering the amounts you might expect from them. If you're pushing the stick 50% of the way with a deadzone of 50%, you'll actually only get 25-30% speed, not 50%. If my understanding of the function is correct, gradually as you push the stick closer to 100%, it will catch up. I presume magnitude is reaching threshold as you are getting some movement.
 
Last edited:

Roastedzerg

Member
The deadzone only adjusted the deadzone from the joysticks resting position in the center to the rim. The issue im having is pushing the joystick all the way to the rim completely to one of the cardinal directions (up, down, left, or right) and slowly moving it towards another direction along the rim. Like, if im moving left, and i ever so slightly start moving the joystick up, the game doesnt register the change in direction till ive moved it a few pixels up. I want even the slightest change of direction to register. To see what i mean, go into game maker, pop in the usual game maker joystick movement code, and push the joystick all the way to the left, then very slowly move it up or down along the rim and you'll see the character gets sort of soft-locked in those 4 directions.
 

O.Stogden

Member
The deadzone only adjusted the deadzone from the joysticks resting position in the center to the rim. The issue im having is pushing the joystick all the way to the rim completely to one of the cardinal directions (up, down, left, or right) and slowly moving it towards another direction along the rim. Like, if im moving left, and i ever so slightly start moving the joystick up, the game doesnt register the change in direction till ive moved it a few pixels up. I want even the slightest change of direction to register. To see what i mean, go into game maker, pop in the usual game maker joystick movement code, and push the joystick all the way to the left, then very slowly move it up or down along the rim and you'll see the character gets sort of soft-locked in those 4 directions.
My code doesn't do this however (I can move cursor in perfect circles), which is why I'm trying to find out what in your code is causing it. I'd assume GM's built-in deadzone as it functions not in the way people might expect, as in once the threshold is met, it gradually builds up from 0, it doesn't just immediately jump to what you have your gamepad axis pushed to. If you set the GM deadzone to 0.25 and you push your joystick to 0.26, it will hardly move at all, as the returned value would be 0.004 or around about that. You may have the deadzone in GM set too high, which means slight movements on an axis will do nothing. Generally I'd never set it above 10% for a decent quality controller.

The manual might explain it better than me, if this is the issue:
GMS2 Manual said:
Using this function does not mean that the axis value will start from the deadzone value, as the function gamepad_axis_value() will always return a normalised value between -1 and 0 or 0 and 1. For example, setting the deadzone to 0.2 will mean that pushing the stick right will only start returning a value from 0 - 1 when the raw axis value is over 0.2 - so when the raw value is 0.2, the return value will be 0, when the raw value is at 0.5, the return value will be 0.375, or if the raw value is 0.9, then the return value would be 0.875.
Moving diagonally on a thumbstick is 50% X axis and 50% Y axis, minus your deadzone setting, so if you have 25% deadzone, that's 37.5% X axis and 37.5% Y Axis, at this point, your magnitude may no longer be exceeding your threshold, and preventing the movement.
 
Last edited:

Roastedzerg

Member
I currently have the deadzone set to 0.25, but i tried it with 0 and it only changed the deadzone from center to rim.
Edit: I'll give it another go when i get back home, pc blue screened when i was working on it lol
 
Last edited:

Roastedzerg

Member
@O.Stogden Took me a while to reply, when my pc bluescreened it corrupted my game file since it happened mid save. Luckily I didn't lose too much. Anyway, i changed the deadzone to 0 and found out that actually was the solution lol I dont know why it didnt work before, maybe when i had to rollback the project it took out some mistake i made before. Thank you!
 
Top