Hello, I was creating a compass UI and I came across this issue in the system where the compass would revolve a full 360-degree spin if it goes from 360 degrees to 0 degrees and vice versa as shown in the video.
https://gyazo.com/f06d9603220c2e7753def7c226d8c643
What it should look like is this:
https://gyazo.com/a6bcda61c53c8100498dae30e5f4ece5
Here’s my code
local cam, camPart = workspace.CurrentCamera, workspace.CameraPart
local absoluteSize = 0
local function partToCamera() camPart.CFrame = cam.CFrame end
local Label = script.Parent.Bearing
local Circle = script.Parent.Rotational
local tweenInfo = TweenInfo.new(0.1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,true)
local tweenInfo2 = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false)
local ts = game:GetService("TweenService")
function Round(n, decimals)
decimals = decimals or 0
return math.floor(n * 10^decimals) / 10^decimals
end
local function moveWithOrientation()
local Or = camPart.Orientation.Y
local deg = 0
if Or < 0 then deg = 180 + (180 + Or) else deg = Or end
deg = 360 - deg
local inc = (absoluteSize * 4) / 360
Label.Text = Round(deg,0)
if deg == 360 or 0 then
local Tween2 = ts:Create(Circle,tweenInfo2,{Rotation = Round(deg,0)}):Play()
else
local Tween = ts:Create(Circle,tweenInfo,{Rotation = Round(deg,0)}):Play()
end
end
moveWithOrientation()
partToCamera()
camPart:GetPropertyChangedSignal("Orientation"):Connect(moveWithOrientation)
cam:GetPropertyChangedSignal("CFrame"):Connect(partToCamera)
I used @TheCarbyneUniverse’s post to create this system so credits to him!