This is really a MATH question.
So rotation of the camera, when clamped to 360 degrees, can be a value between -360 and 360
So if i take the absolute value of the rotation, it will be a number between 0 and 360
Then i see where it falls between increments of 45 degrees
So it can be between:
0-45
45-90
90-135
And so on
Depending on where it lands, i rotate the camera to look at the NEAREST 90 degree increment resulting in camera looking up/down/left/right
I have a VERY long if/else if chain handling this fine; but my brain has convinced me there is a faster math way that wont take up long lines of code
My brain says:
-you can use division to divide the absolute value of the rotationY of the camera by 45/90/something resulting in a decimal
-then remove the whole numbers until you are left with a decimal
-then round up or down to find 0 or 1 to determine the direction to rotate the camera towards.
-Then use the actual rotation value to determine how many degrees in the found direction the camera must move to reach it’s nearest 90 degree resting increment.
-Then apply negative or positive rotation to the camera depending on the original negativity/positivity of the rotation value
And all this using only a few lines of code!
My brain says its possible. But I can’t visualize it. Is my brain wrong?
Anyone have any ideas?
P.s. the existing code is ugly and long and I’m embarrassed by it. It’s just a long line of if/else if
P.p.s. I’m using craft and the camera dependancy. (Making my own camera)
Thank you for your time,
-Timmy_theBarbarian