i am messing with a retro - like concept, where i have everything's position rounded to the nearest whole(via CFrame) and have their orientation is rounded to nearest 45 degrees, or 2pi / 4 in radians(also via CFrame). I am encountering problems with the latter as i am yet to find a good way to round it to the nearest 2pi / 8(since it is in radians, the math.floor thing is practically rendered useless). Currently i am alternating between two methods, which are:
1: converting an object's rotation(in radians) into degrees before rounding it to the nearest 45 degrees and converting that back into radians
and
2: referring to a table of angular revolution (in radians(e.g, (2pi / 8 * 1), (2pi / 8 * 2), (2pi / 8 * 3), etc)), finding the one closest in proximity to the object's actual rotation(in radians) and changing the object's rotation to that.
I feel these methods are pretty trashy, and wanna find a more clean - cut one(like, just directly rounding the radians to the nearest 2pi / 8 without, say, any conversion or referral of a table). So pls help
thx a lot
Actually math.floor is your answer, you just need to use it correctly:
local rotation = --insert actual part rotation here local rotationStep = (2*math.pi)/8 --BTW you can just use math.pi/4 local newRotation = math.floor((rotation/rotationStep)+0.5)*rotationStep
Edit: added 0.5, to round to the nearest angle