I am trying to make this simple compass but I ran into a problem. When my camera is looking down or up the angles are messed up and I can’t figure out how to fix it.
The angle shouldn’t change when I move the camera to face up or down. Can anyone help me? I don’t know what to do.
Here’s how I got the angle:
local orientation = math.deg(camera.CFrame.LookVector:Angle(Vector3.new(0, 0, -1), Vector3.new(0, 1, 0)))
if orientation < 0 then
orientation = orientation + 360
end
I’m not sure what the reason is, but I think I found a solution. You could simply use only the X and Z of the Camera’s LookVector and it should work just fine.
Modified version of your code:
local yLessLookVector = camera.CFrame.LookVector * Vector3.new(1, 0, 1)
local orientation = math.deg(yLessLookVector:Angle(Vector3.new(0, 0, -1), Vector3.new(0, 1, 0)))
if orientation < 0 then
orientation = orientation + 360
end