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:
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?
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;
Last edited: