How do you make angles from 0 - 360 and not from 0 - 180 & -180 - 0?

Expectation:


Reality:

This is how my script looks like rn; :((

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)
1 Like
CFrame = CFrame * CFrame.Angles(math.rad(359),math.rad(90),math,rad(33))

math.rad take’s degrees and turns them into radians. CFrame.Angles takes radians.

I know. I don’t think I need CFrame here since I’m not dealing with the 3D World.

1 Like

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)

Yes, I did just that even earlier and this is what I got;

Strange… This is what I got:

2 Likes

You can also use modulus.

print(-90 % 360) -- 270

Full circle example:

for i = 0, 180, 10 do
	print(i, "\t", i % 360)
end
for i = -180, 0, 10 do
	print(i, "\t", i % 360)
end
2 Likes

Oh, I see what I did wrong, thanks. But now this is how things are going;


I guess that isn’t really that bad but is there a way to make it like this? v

Oh, I get it now! Thanks much, mate!!! <3