When i was first learning about math.atan2 the person in which i was learning it from
substracted y2 with y1 and x2 with x1 which does the same thing as when i don’t substract them .
Gif without substracting:
https://gyazo.com/f50ebaf648d80d2c5171fd7578cbe8e1
Gif with substracting:
https://gyazo.com/68e9862ec9a3ab199442356936b9db63
Script without substracting:
local Angle = 1
local Radius = 50
function Upd()
local x = math.cos(Angle)*Radius
local y = math.sin(Angle)*Radius
script.Parent.P2.Position = script.Parent.P1.Position+UDim2.new(0,x,0,y)
script.Parent.P1.Rotation = math.deg(math.atan2(y,x))
end
while true do
if Angle == 360 then
Angle = 1
else
Angle = Angle+.1
end
Upd()
wait()
end
Script With substracting:
local Angle = 1
local Radius = 50
function Upd()
local x = math.cos(Angle)*Radius
local y = math.sin(Angle)*Radius
script.Parent.P2.Position = script.Parent.P1.Position+UDim2.new(0,x,0,y)
script.Parent.P1.Rotation = math.deg(math.atan2(y-script.Parent.P1.Position.Y.Offset ,x-script.Parent.P1.Position.X.Offset ))
end
while true do
if Angle == 360 then
Angle = 1
else
Angle = Angle+.1
end
Upd()
wait()
end
i’d like to know why he substracted y2 with y1 and x2 with x1 please and thank you.