Qlak
Member
Hey guys!
I'm having hard time when it comes to checking angles.
I managed to achieve what I wanted, but I'm sure that there must be a better way, because my code is not clean for sure.
Maybe you could help me out :
-For instance, imagine that you have traditional top-up 2d shooter, left stick is player movement and right stick is aiming.
-You can get angle of each joystick with code like:
-It gives you the angle of each joystick in degrees 0-359.
Lets say that you want character to be faster, when running the same way he looks at with +-20 degree margin (so when both sticks point more or less the same angle).
In theory you can achieve it this way:
It works perfectly untill you get to 19 or 340 degrees, because after it reaches 360 it becomes 0.
I managed to do it in far too many lines of code, and I was hoping you can show me simpler solution to this problem?
I believe it's something rather common. How do you handle this 359-0 angle change?
Thanks for your help in advance!
I'm having hard time when it comes to checking angles.
I managed to achieve what I wanted, but I'm sure that there must be a better way, because my code is not clean for sure.
Maybe you could help me out :
-For instance, imagine that you have traditional top-up 2d shooter, left stick is player movement and right stick is aiming.
-You can get angle of each joystick with code like:
GML:
var rightStickHorizontal = gamepad_axis_value(controllerNumber, gp_axisrh);
var rightStickVertical = gamepad_axis_value(controllerNumber, gp_axisrv);
rightStickAngle = point_direction(0, 0, rightStickHorizontal, rightStickVertical);
var leftStickHorizontal = gamepad_axis_value(controllerNumber, gp_axislh);
var leftStickVertical = gamepad_axis_value(controllerNumber, gp_axislv);
leftStickAngle = point_direction(0, 0, leftStickHorizontal, leftStickVertical);
Lets say that you want character to be faster, when running the same way he looks at with +-20 degree margin (so when both sticks point more or less the same angle).
In theory you can achieve it this way:
GML:
if(leftStickAngle < (rightStickAngle + 20) && leftStickAngle > (rightStickAngle - 20)){
maxMovementSpeed = runningSpeed;
}
I managed to do it in far too many lines of code, and I was hoping you can show me simpler solution to this problem?
I believe it's something rather common. How do you handle this 359-0 angle change?
Thanks for your help in advance!
Last edited: