use ATan2(). It gives the angle from -180 to 180 with 0 pointing right. Just add 360 if the result is less than 0
Angle = ATan2(yd,xd) 'notice that yd is first parameter ' |-90 ' | ' -180 | 0 '------+------ ' 180 | 0 ' | ' |90 If Angle < 0 then Angle :+ 360 ' |270 ' | ' 180 | 360 '------+------ ' | 0 ' | ' |90