From 7aab7ea7d6aca1b24e721ae984dfe30b0962a24f Mon Sep 17 00:00:00 2001 From: C o u r t e n a y Date: Sat, 4 Nov 2017 14:50:49 +1300 Subject: [PATCH] Fix angle calculation Angle returned from atan can be < 0, fixes this (copy solution from JS bot) --- airesources/Ruby/hlt/entity.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/airesources/Ruby/hlt/entity.rb b/airesources/Ruby/hlt/entity.rb index 76898499..92882d67 100644 --- a/airesources/Ruby/hlt/entity.rb +++ b/airesources/Ruby/hlt/entity.rb @@ -29,6 +29,8 @@ def calculate_distance_between(target) # return: Angle between entities in degrees (float) def calculate_angle_between(target) radians = Math.atan2(target.y - y, target.x - x) + radians = radians + 2 * Math::PI if radians < 0 + radians/Math::PI * 180 end