Compass system help

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!

Instead of using tweening set the position with trigonometry. What we have here is the degrees (relative to origin?) and the magnitude of the frames to the origin. We are basically just applying a sine and cosine offset from there origin at an angle of 0 degrees.
If we simply treat the sine as y and the cosine as x we can simply do this to get the position from the angle

local curAngle = 90
local x = math.cos(curAngle)
local y = math.sin(curAngle)
frame.Position = Udim2.new(offsetOrigin + x, offsetOrigin+y)

You can play with it here Angle (Degrees) and Unit Circle

The script doesn’t work by moving the position, it works by rotating the ImageLabel as shown in the picture

Don’t know about that then, I guess you can multiple the orientations to get a local rotation of them relative to the rotation of the compass

I just saw someone referenced this topic so I decided to share the solution we used,
instead of Tweening the compass rotation we decided to just change the “rotation variable” of the image label.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.