Angles lock - Please help

Greetings Devs

I hope you are well

I am in need of help and I have been scratching my head for the past two days. I have the player represented as turret however the turret should only have a 180 degree turn depending on the side they are so - The turrent follows the mouse cursor

e.g If they are on the top then they should only be able to go from 180 to 0 degrees or if they are on the right side, Then they should only be able to go from 270 to 90 - if that makes sense

I was able to get the right hand side but I am struggle with the other sides, when its on the top side, and it reaches 180, then the turret auto “locks” or turns to the 0 degree however when I try going past the 0 degree mark then it doesnt. Not auto locking to the 180 degrees.

Any assistance would be appreciated. Thank you in advance


That right facing object is a pain, and has been the stumbling block of many-a-developer. It changes from 359 to 0, and is tricky to work with. Here’s something I cobbled together, which I think does what you’re after.

Note, I left the min and max angle calculations in, so you understand how those values are calculated:


And here’s what it looks like:

Turrents

2 Likes

This is soo true (even with 180° i had the same issue dunno if something changed)

I wonder why we can’t use Angles in the Cartesian plane where angles are positive…
And e.g the flip could be at 90/270 for y and 0/180 for x axis…

1 Like

@Keith_1357 @RMDB For me this is perfect situation to actually teach any1 how to properly use OR and AND

I do not even see it as something problematic cause once you understand what you need to do it is brain dead simple

@Riabuz Look closely

We want to get range (FOR LEFT) from BELOW 225° and above 135° indicated by red

And range (FOR RIGHT) that would be above 315° but less than 45°
Which does not make sense

What does make sense is you want to check range if its greater than
315° and less than 360°
While also check if it is greater than 0° but less than 45°

But you need to make them both (ones for right) even being separate checks act as same exact check

SOOOO

We use here OR (if one these conditions is true)
To have multiple options return condition as true
BUT at the same time we have 2 AND (of all of these conditions are true)
So we simply split range we check into two parts where angle in which there is that not natural jump over value we take as our end/start point for each scenario

Where at the same time BOTH now will return this condition as true

And now looking on image of ranges at the beginning of this post
And image with events
You can determine whatever the hell angle range you want
And nothing is troublesome here anymore

And just to be perfectly clear

Same exact BS can be applied if angles we checks are this way

Just in this case left side is where you need to split range

1 Like

There’s a typo with the first condition in the second event. It should read Player > 315.


This can be made the same as your previous angles image if you use mod(angle + 360, 360). That’ll put the angle in the 0-359 range.

1 Like

DO NOT QUESTION GREATNESS!!!

I am dyslectic what did you expect?

Fixed

1 Like

I know but for sake of someone understand how to abuse angles i would introduce modulo AFTER someone know how to handle angles check

It is probably not related to OP issue but on how GD handle rotations/angles.

When u rotate toward angle from 0 to 180, at 180-180 pos the item flip for a millisecond bcs ofc 2 angles can’t coexists at the same pos…use the +180 trick doesn’t solve the problem, same if u stop at 179 and thwn flip at 180…i dun want to go in depth but i’ve spent a whole year on this and there is no solution.
this makes any object wrongly flip and to me is a bad behaviour.

As i said above I wonder why we can’t use Angles in the Cartesian plane where angles are positive…
this will fix a lot of problems…but i’m no dev …so i guess it’s like this for reasons…

2 Likes

Simply bcs if i want to rotate an object toward my mouse from 0 to 180° i want it to happen without issue.

1 Like

When i came up with this formula one dev did same thing WITH using SOME expression suing only ONE angle check for each side
It was one of 1st thing i did discover on my own when i came here
And i was so amazed by how lucky i was to figure it out
I did not even think that it would be good idea to screenshot that expression

And i do not remember what expression it was

BUT at the same time i am not 100% sure if it was purely for checking range
Where i think it was expression for turn itself being made with shortest possible way
So when you have player in top left and you want it to rotate right
It would not go counter clockwise but clockwise
I really do not remember what it was about cause it was like 2 years ago
But for sure something to help exist
Where i am same as your opinion
I would expect for it to just work instead of us jumping around trying to make it work as we expect it to work

2 Likes

I find you could have the turret check the x or y (depending on how you want it set up) coordinate of the cursor and if is past the turret then have it not follow the command. Hope this helps :slight_smile:

1 Like