Find the rotation between 2 points on a GUI

I’m not really that good at math and I don’t fully understand a lot of the Lua math functions. I have 2 points on a screen right now, one being a frame.
image

I’d like to know the best way to go about pointing A at B by rotating it.
image

The issue I’m facing is that I don’t know how to properly find the angle I have to set the rotation to. I’m pretty sure we covered this during my geometry class in school, but I don’t remember any of that.

You can use trigonometry do this.

Try this:

--//Variables
local mouseA = script.MouseA
local mouseB = script.MouseB

--//Initialization
local distance = mouseB.Position - mouseA.Position

local vector = Vector2.new(distance.Width.Scale, distance.Height.Scale).Unit
mouseA.Rotation = math.deg(math.acos(vector.X)) * math.sign(math.asin(vector.Y))

Here’s a really good explanation on the functions:

1 Like

Implemented it and it worked, thank you so much! I’ll look into the post

1 Like

No problem. If you have any more questions, feel free to ask.

1 Like