I am making a gui where there is an image facing where a dummy is, but the angle doesnt go to the right. The gui item only stays on the left side, and when i turn 360 degrees, it goes to the bottom, then back to the left, when its supposed to wrap around. Basically, the part where
AngleRadians is defined, it is only defined to be a part of 1 pi, not 2pi
This is my code:
local RADIUS = 0.5 local ANGLE_OFFSET = 90 RunService.RenderStepped:Connect(function() local DetectionNPC = workspace.DetectionNPC.PrimaryPart local HumRoot = Character:WaitForChild("HumanoidRootPart") local Facing = Character.HumanoidRootPart.CFrame.LookVector local Vector = (DetectionNPC.Position - HumRoot.Position).Unit local AngleRadians = math.rad(math.deg(math.acos(Facing:Dot(Vector))) + ANGLE_OFFSET) local Position = UDim2.new(.5 + RADIUS * math.cos(AngleRadians) - Button.Size.X.Scale / 2, 0, .5 - RADIUS * math.sin(AngleRadians) - Button.Size.Y.Scale / 2, 0) Button.Position = Position Button.Rotation = -(math.deg(AngleRadians) - ANGLE_OFFSET) end)
Basically, there is no difference between say 10 degrees facing left of the detection npc, and 10 degrees facing right of the npc, which means the fix is somewhere in this line of code:
local AngleRadians = math.rad(math.deg(math.acos(Facing:Dot(Vector))) + ANGLE_OFFSET)
I have noticed that the minimum and maximum threshold it goes up/down to is about 1.57 and 4.7, not 0 and 2pi, but im not really a professional at the math functions.