Trying to rotate a GUI relative to another GUI

I am trying to create a “Breadcrumb” system for finding buried treasure, but I am having trouble rotating the gui relative to the previous gui.

The gui seems to rotate at the moment but they are slightly off so I assume my math must be wrong.

I was thinking that using tangent would work, because I know the length of opposite and adjacent. I think I am close but I just need some quick help. Should I be doing the parts position instead of the screen position?

Sorry for the indendting, its part of a larger function.

				local CurrentVector, CurrentVectorOnScreen
				local PreviousVector, PreviousVectorOnScreen
				if PreviousWaypoint == nil then
					CurrentVector, CurrentVectorOnScreen = Camera:WorldToScreenPoint(Object.Position)
					PreviousVector, PreviousVectorOnScreen = Camera:WorldToScreenPoint(Character.PrimaryPart.Position)
				else
					CurrentVector, CurrentVectorOnScreen = Camera:WorldToScreenPoint(Object.Position)
					PreviousVector, PreviousVectorOnScreen = Camera:WorldToScreenPoint(PreviousWaypoint.Position)
				end

				local Angle = math.atan2(CurrentVector.X - PreviousVector.X, CurrentVector.Y - PreviousVector.Y)
				
				ClonedBreadcrumbFrame.Position = UDim2.new(0, CurrentVector.X, 0, CurrentVector.Y)
				ClonedBreadcrumbFrame.Rotation = 0 - math.deg(Angle)

Also heres a gif, you can see they are slightly off.
https://gyazo.com/712fc3bafa3c09b300f03c5e0120714c

Thank you and have a good one!

1 Like

I skimmed through your code and from what I can tell, the frames rotation is off because you’re not compensating for the 36 pixel offset which is created by the GUI inset at the top of the screen.

Try changing PreviousVector.Y to (PreviousVector.Y-36)

2 Likes