How would I make a GUI object rotate towards another GUI object?

As the title suggests, how would I make GUI object face towards another GUI object? It’s easy to do this if we were to make one part face towards another part because we can just do this BasePart.CFrame =, AnotherPart.Position). But there is no way of doing that with a GUI object. So can anyone tell me how it can be done?

1 Like

Wouldn’t you use TweenService if you wanted to rotate a GUI Object to another GUI Object?

Tweens are used to interpolate the properties of instances. These can be used to create animations for various objects such as GuiObjects.

That’s not what I meant in my question. If you were to do this with normal BaseParts, you would do Part.CFrame =,AnotherPart.CFrame)-- Makes the Part face towards the other How would we do this with GUI objects?

You can try using math.atan2(offsetx, offsety) to get the angle in radians from the center of the ui to that offset. Example image:

1 Like

I meant math.atan(offsety, offsetx), but for some reason it errors when trying to edit my message.

Can you explain to me what those mathematical functions are?

local a, b = script.Parent.Frame1, script.Parent.Frame2

--//Direction vector with a length of 1, we can use the atan2 function to find the angle if we were to graph this
local direction = (b.AbsolutePosition - a.AbsolutePosition).Unit

--//atan2 returns the angle in radians, so convert it to degrees
local angle = math.deg(math.atan2(direction.Y, direction.X))

a.Rotation = angle

--//a will be rotated towards b
1 Like

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