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?
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.
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.