# How to find the angle from the direction the mouse has moved to?

Aye, yo. I’m tryna get the angle (θ) (θ - greek small letter theta (u+03B8) copy and paste - Unicode® symbol)) from the direction of where the mouse has moved. I was thinking I have to use some sort of trigonometry. Thing is, I don’t know trigonometry. ;-; But here’s my initial thought;

What I have so far;

``````local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

local center = Vector2.new(500,500)

local origPos
local endPos

mouse.Button1Down:Connect(function()
origPos = Vector2.new(mouse.X, mouse.Y)
end)

mouse.Button1Up:Connect(function()
endPos = Vector2.new(mouse.X, mouse.Y)

local length = (endPos - origPos).Magnitude
end)
``````
1 Like

The angle itself would just be `math.atan2(dy,dx)`, with `dy` and `dx` being the difference between `endPos` and `origPos`'s vector components.

1 Like

Can u explain what `dy` and `dx` exactly are? :(( Thank you!

Ok. I solved it! Thanks for the help mate!

``````local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

local origin
local endPos

mouse.Button1Down:Connect(function()
origin = Vector2.new(mouse.X, mouse.Y)
end)

mouse.Button1Up:Connect(function()
endPos = Vector2.new(mouse.X, mouse.Y)

local length = (origin - endPos).Unit --idrk, i just called it length

local angle = math.deg(math.atan2(length.Y, length.X))
end)
``````
1 Like