Hello World!
I am attempting to check the difference in rotation (in degrees) of two CFrames in a clockwise rotation.
I have been unable to find any resources on this specific issue, although I have found many topics that were VERY similar. I searched Scripting Helpers, here, google, and tried some of my own fruitless experiments. I even tried all 3 solutions in this post. So far I have this:
local Facing = Building.PrimaryPart.CFrame.LookVector
local Vector = OldBuilding.PrimaryPart.CFrame.LookVector
local Angle = math.acos(Facing:Dot(Vector))
local Degrees = math.deg(Angle)
This returns the amount of degrees of difference, but the issue is that it will only report it in the nearest direction, not clockwise (e.g. Both 90 and 270 return as 90 degree difference). I want to get the difference in degrees in a clockwise motion (e.g. 90, 180, 270, 360).
Edit: It would also suffice if the counterclockwise 90 degrees would report as -90. Either solution would be welcome!
Am I going to be able to utilize what I have here, or am I not even close? I have a hard time understanding math with CFrames. I feel like what I have here may only need a tiny adjustment. Any assistance is appreciated!
PS: If anyone knows a better way to round the degrees to the nearest 90, please advise!
local RoundOptions = {0, 90, 180, 270, 360}
local ClosestOption = 0
for i, roundOption in ipairs(RoundOptions) do
if math.abs(Degrees - roundOption) < math.abs(Degrees - ClosestOption) then
ClosestOption = roundOption
end
end
I need it to return to the nearest 90, precisely. Without this it was returning values very close, but not precise. My concern is that over enough rotations my Building would no longer be lined up with the Grid I have.