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

GameMaker [Resolved] Simple question regarding normalizing input after setting gamepad deadzone

Nixxi

Member
Can someone point me to a simple example of how to normalize the analog input from a gamepad thumbstick after setting the controller's deadzone? Google is being super unhelpful. :-/

Here's what I'm working with:
Code:
/// Create Event
gamepad_set_axis_deadzone(0,0.2);

/// Step Event
var hlaxis = gamepad_axis_value(0, gp_axislh);
var vlaxis = gamepad_axis_value(0, gp_axislv);
var dir = point_direction(0,0,hlaxis,vlaxis);
var vel = point_distance(0,0,hlaxis,vlaxis);
var max = 10;
/* Need to normalize vel from deadzone */
speed = clamp(vel*max,0,max);
direction = dir;
Obviously it's not great, because as soon as the stick leaves the deadzone, the player speed immediately jumps from 0 to 2+ in a single frame because 'vel' needs to be normalized in the range of 0.2 to 1.0 - how do I do this and/or what sort of math is involved?
 
Last edited:

NightFrost

Member
So you're saying you want to remap 0.2 - 1.0 range to 0 - 1.0 range? Googling finds this stackoverflow question, which gives the formula:
Code:
low2 + (value - low1) * (high2 - low2) / (high1 - low1)
Where low1, high1 is your original range, low2, high2 is target range and value is what you want to remap.

Edit - also, 0.2 may be too much deadzone. Try moving right, and then just a little bit up or down at the same time. Chances are, you're still moving directly right. High deadzones kill movement angles that are close to cardinal directions.
 

Nixxi

Member
Thank you for this, I was using the wrong term for my search - "remap" is the correct term? I was searching with "gamepad analog deadzone normalize gms2" and half a dozen other variations of that query.

So you're saying you want to remap 0.2 - 1.0 range to 0 - 1.0 range? Googling finds this stackoverflow question, which gives the formula:
Code:
low2 + (value - low1) * (high2 - low2) / (high1 - low1)
Where low1, high1 is your original range, low2, high2 is target range and value is what you want to remap.
Yes, this is exactly what I was looking for!

Edit - also, 0.2 may be too much deadzone. Try moving right, and then just a little bit up or down at the same time. Chances are, you're still moving directly right. High deadzones kill movement angles that are close to cardinal directions.
I set it that high to prevent stick-flicking (or whatever term best describes the action of pulling the analog stick and then releasing it, causing the stick to "flick" in the other direction) - I don't have a good solution for this, but that's a topic for another thread. Again, thank you for the help! :)
 
Top