I wanted to ask if there is any way that the functions result will be somewhat unaccurate or would have an error or if the output would be incorrect. This function basicly would return the angle between two objects giving the angle for the enemy to aim at the player or pointing at the player.
import math
def computeOrientation(enemy_x, enemy_y, player_x, player_y):
# Compute the angle between enemy and player taking into account image axis
player_b = enemy_x - player_x
player_a = enemy_y - player_y
if player_a == 0 and player_b > 0:
return 90
elif player_a == 0 and player_b < 0:
return -90
elif player_a == 0:
return 0
if player_a < 0:
angle = math.atan( player_b / player_a)
return int(round((math.degrees(angle)-180))
else:
angle = math.atan(player_b / player_a)
return int(round((math.degrees(angle)))
positions = input()
enemy_x_str, enemy_y_str, player_x_str, player_y_str = positions.split(",")
enemy_x,enemy_y,player_x,player_y = int(enemy_x_str), int(enemy_y_str), int(player_x_str), int(player_y_str)
angle = computeOrientation(enemy_x, enemy_y, player_x, player_y)
print(angle)
I've tried adding a lot of rounds but it still said that it was wrong. Help thanks