Mookal
Member
I'm making a game where the character's speed is analog, based on how much the player pushes the left stick on a connected controller. I'd think finding the distance between the joystick's position and its origin would be simple:
Unfortunately, this ends up causing a pretty major problem. While the area the joystick can move around in is a circle, that area is interpreted as a square.
So pushing up on the joystick would put its position at the top center of the square, but pushing both up and right on the joystick would put it in the top right of the square.
This means that, when the joystick is pushed towards a corner, the distance it's being pushed is overestimated.
I understand this concept is pretty abstract, so here's a diagram:
Essentially, I want the interpreted distance from the origin to be the same no matter what direction the stick is held in, while also keeping analog movement. How can I achieve this?
GML:
var xpos = gamepad_axis_value(0, gp_axislh);
var ypos = gamepad_axis_value(0, gp_axislv);
var dist = point_distance(0, 0, xpos, ypos);
return dist;
So pushing up on the joystick would put its position at the top center of the square, but pushing both up and right on the joystick would put it in the top right of the square.
This means that, when the joystick is pushed towards a corner, the distance it's being pushed is overestimated.
I understand this concept is pretty abstract, so here's a diagram:
Essentially, I want the interpreted distance from the origin to be the same no matter what direction the stick is held in, while also keeping analog movement. How can I achieve this?