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 direction = (origin - endPos)
local angle = math.ceil(math.deg(math.atan2(direction.Y,direction.X)))
if angle == angle then
if angle < 0 then
angle = math.abs(angle) --idk what to do from here ;-;
end
end
print(angle)
end)
To transform your angle from the range [-180,180] to [0,360], you just need to add 180 to the resultant angle. From there you can play with the “direction” of the circle so to speak by changing the signs of direction.X and direction.Y. For instance, to get results in like in your [0,360] image (with a clockwise direction and negative-X start point), you could use this code:
mouse.Button1Up:Connect(function()
endPos = Vector2.new(mouse.X, mouse.Y)
local direction = (origin - endPos)
local angle = math.ceil(math.deg(math.atan2(-direction.Y,-direction.X)))
if angle == angle then
angle += 180
end
print(angle)
end)