Legacy GM [SOLVED] Rotation angle limiting



I'm having trouble adapting some code.

I have a stationary turret that the player can pan back and forth by changing its image_angle with the arrow keys.
I want to limit its rotation to a minimum and maximum angle from its original position.
The tutorial I followed does exactly what I want,
but it calculates the angle difference using mouse position rather than a set location.

Here's what I have now ---> in the step event:
pointDir = point_direction(x, y, mouse_x, mouse_y);
base_angle = image_angle;
delta = max(-minMaxAngle, min(minMaxAngle, angle_difference(pointDir, base_angle)));
image_angle = scr_angleRotate(image_angle, base_angle + delta, rSpeed);
In the script ---> scr_angleRotate:
angle = argument0;
baseDiff = argument1;
rotateSpeed = argument2;

calc = angle + median(-rotateSpeed, rotateSpeed, angle_difference(baseDiff, angle));
return calc;
I want it to have a full angle of 30 degrees so I've set minMaxAngle to 15.
I think I just need to change the (mouse_x, mouse_y) part but I can't figure out what to change it to for the life of me.


Well, shoot.
You're just solving all of my problems today.
Thank you!
That clamp function it's so useful, a parameter limiter. Neat, very neat indeed.

No wonder it isn't build-in GM 8. No worry, shouldn't be too hard to build one each time you need one.


I have a similar but much easier question. How do I set an image_angle max for the following line?

if (btnState = 1) {
image_angle = image_angle + 10;

Or is the max something I should set elsewhere (like in a Create Event)? If so, how do I do that?

Basically, if my button's state = 1, I want the object it controls to rotate 180 degrees and stop. . .

Thanks so much.


If it is just a maximum you want to set, you can do
if(image_angle < 180) image_angle = min(180, image_angle + 10);