How do I properly use math.deg with guis?

I’m trying to make a gui face the position of a part on the map.
However, when rotating the gui, for some reason, math.deg caps at -89 degrees and goes back the other way around, instead of going all the way to -360 degrees,

Here is the code:

while wait() do
	local CF = camera.CFrame:ToObjectSpace(workspace.Part.CFrame)
	local x, y, z = CF:ToEulerAnglesXYZ()
	
	local number = math.deg(y)
	player.PlayerGui.DamageGui.ImageLabel.Rotation = number
end

Does anyone know how to make math.deg loop the whole way around in this situation?

are you sure ToEulerAnglesXYZ returns radians?

does it work at all currently, and just clamp off at 89? Or does it not work at all?

It works but once it reaches more than 89 or -89 it counts back to 0. So yes, it just clamps.

try adding prints to see what your values are before and after the math.deg operation

Apparently Y clamps at -1.5, preventing further rotation.

I may be unsure about what youre trying to do here. I plugged your code into studio, and I would move my player around the part. Nothing happened to the frame, because my cameras orientation wasnt changing.

This is what I was trying to achieve.

The trick is, have a UDIM(0,1,0,1) part where you want the center to be. And then under that, have the damage image. Then you rotate the parent frame, which is that really small square, and the stuff under it will rotate with it. No need for trig

I put a Frame with the size of {0, 1, 0, 1} and the position of the middle of the screen with the damage image in it. Nothing really different happened compared to how I was doing it.

I’m not sure, but it seems that the CFrames of objects are constructed in Z, X, Y order somehow (?) (would appreciate an explanation). Meaning using :ToEulerAnglesYXZ() instead works.

I switched around the values a bit, y (the second value) seems to work the best. I just need to somehow make it so once it goes past 1.5 (which is the max it goes to) it loops around to 3 then goes to 0 instead of going back to -1.5.

ToEulerAnglesXYZ() will never return a value below -90 or above 90 degrees on the Y axis. It’ll always go up to 90 and then start counting back down.

I have no idea why it does this but you can’t use ToEulerAngles() for this - you’ll have to do some manual trigonometry with the LookVector of the camera’s CFrame to determine the angle.

I think remember I used math.atan2 with the X and Z of the LookVector as the arguments to get the angle, so play around with that.

That isn’t how you’d handle such a thing. Like @NotAstrain said you can use atan2 like so:

local targetVector = camera.Position - workspace.Part.Position
local angle = math.atan2(targetVector.X, targetVector.Z)
player.PlayerGui.DamageGui.ImageLabel.Rotation = math.deg(angle)
1 Like

It kind of works a bit better, but at different angles it doesn’t work.
This is a good place to start off of though.

NEVERMIND OH MY GOD I DID IT THANK YOU SO MUCH

1 Like

Nice! You can use atan2 in a lot of situations so it’s always good to know some trig when making a game!