AI - Detect relative position of 2 objects

I’m currently making a 2D flight game and I’m having trouble with the AI.

The AI is going to have to modes, defense and attack.

1194184--47253--$2ls75mv.jpg

In locations 1 and 2 the AI will be attacking and in 3 and 4 it will defend, the plane in the middle is the player and the other is the enemy.

I managed to get the angle from the 2 vectors expecting to range from 0 to 360 and that way I’ll limit the zones, however it didn’t.
Instead each of the sections varies from 0-90 and it’s positive in 2 and 3 and negative in 1 and 4.

Can someone give me advise on what to do ? The main objective of this is to know where the enemy is relativly to the player the rest of the code is done …

Here is the code I used:

Alpha = (Mathf.Atan((enemy.z - player.z)/(enemy.x - player.x)) * Mathf.Rad2Deg

I’d inverse-transform the position of the enemy into local space of the player plane. This will give you the position of the enemy relative to the position of the player.

Then you can just check that position’s x, y and z values to see where the enemy is.

It works ! I just need to calibate it. It says that it’s in the front in 2 and 4 and behind in 1 and 3 …