If you know the position of where the tank shot, then you can calculate the direction using a dot product. I'm writing this off memory, so it might need a little adjusting, but the code should be something like this:
# shot_pos = position of the impact to the tank
# convert the shot position to a position relative to the tank
var local_shot_pos = get_global_transform.xform_inv(shot_pos)
# normalize the local position so it has a length of 1
local_shot_pos = local_shot_pos.normalized()
# cache the results of half of PI (90 degrees) for conditions
# later in the code
var half_pi = PI * 0.5
# using a dot product, we can tell how far of an angle we would need
# to get from one direction to another. This will tells us how 'close' to the
# direction the shot is, allowing us to tell which direction it came from
#
# NOTE - the dot does not tell direction, just distance, so that is why we are using 90
# degrees instead of 180, as we want to detect angles 90 degrees on either side of the direction
#
# is the shot above/below
if (Vector2(0, 1).dot(local_shot_pos) <= half_pi):
print ("Shot was above!")
elif (Vector2(0, -1).dot(local_shot_pos) <= half_pi):
print ("Shot was below!")
# is the shot left/right (might be flipped)
if (Vector2(1, 0).dot(local_shot_pos) <= half_pi):
print ("Shot was right!")
elif (Vector2(-1, 0).dot(local_shot_pos) <= half_pi):
print ("Shot was left!")
The code should detect if it's above or below, and whether it's right or left. To detect just left, right, up, or down, you would need something like this:
# shot_pos = position of the impact to the tank
# convert the shot position to a position relative to the tank
var local_shot_pos = get_global_transform.xform_inv(shot_pos)
# normalize the local position so it has a length of 1
local_shot_pos = local_shot_pos.normalized()
# cache the results of a quarter of PI (45 degrees) for conditions
# later in the code
var quarter_pi = PI * 0.25
if (Vector2(0, 1).dot(local_shot_pos) <= quarter_pi ):
print ("Shot was above!")
elif (Vector2(1, 0).dot(local_shot_pos) <= quarter_pi):
print ("Shot was right")
elif (Vector2(0, -1).dot(local_shot_pos) <= quarter_pi ):
print ("Shot was below!")
else:
print ("Show was left")
I haven't tried the code though, I just wrote it from memory, so it might need adjustments before it works fully.