I've been trying to make a dynamic - map gui, which rotates based on where your camera is looking.
Getting where my camera is pointing in 3d space is easy, but I can't figure out the correct math formula to convert Vector3 to degrees/radians.
Any help would be most appreciated!
This page should be helpful here.
Assuming you only care about the direction they're facing, and not whether their looking up or down, you only need to care about their Heading:
local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = game.Players.LocalPlayer.Head.CFrame:components() heading = math.atan2(m02, m22) --This is in radians! game.Players.LocalPlayer.PlayerGui.ScreenGui.Minimap.Rotation = math.deg(heading) --That line of course requires some modification, since a heading of `0` is pointing along the x-axis, which may not be what you want.
Although this question already has a verified answer, I thought I would also give my solution for other users.
Rather than using the head, as demonstrated by adark, you can use the Camera object to get the direction as specified in the question, here's how:
local cameraLookVector = workspace.CurrentCamera.CoordinateFrame.lookVector game.Players.LocalPlayer.PlayerGui.ScreenGui.Minimap.Rotation = math.deg(math.atan2(cameraLookVector.Y, cameraLookVector.X))
This will now make the Minimap rotate with the Camera, rather than just the Head while only needed one variable as oppose to 12! You may need to add -180 to 180 degrees onto this angle to properly orientate the Minimap.