Modifies the animation of an object based on its angle relative to a position or object

Hello, I have a problem that I thought was solved but not. How can I practically change the animation of an object depending on the angle with respect to another object (for example, if it is with respect to another object from the side, from the front, from the back)?
I tried many ways, calculating the range of angles of each object and comparing, in many different ways. Some work approximately but have frequent errors. I have not found any method that is really effective, much less simple.
image

With the arrows I outline where each object is facing. I need to vary the animation of the red object depending on the blue object. It must be taken into account that the angles are not always multiples of 90, but there may be intermediate ones (which is equivalent to a range of ±45 degrees for each side, which would be, from the front, from one side, from the other and from behind).
I think it is more practical to talk about an angle with respect to a position, since the blue object is always facing it. I have also tried the “AngleTo” position or object function, but none of them work correctly. Also, I think there is a drawback in one of the two objects. I think that on one object it calculates the range of angles from 180 to -180 and on the other from 0 to 360.