angle for animation calculated from a right triangle

I’ve been making a top down game where the Zombie (red) tries to kill The Fighter (blue). For animations I need to know the angle between them. I’ve tried this code where the angle is calculated from a right triangle. I’m somehow receiving wrong results and I don’t know why.
Script is attached to zombie.

I’m not sure if there is better method out there, but if you know one, please inform me about it.
Thanks :slight_smile:

      Hypotenuse = Vector2.Distance(transform.position, Fighter.transform.position);
        Cathetus_End_pos = new Vector2 (transform.position.x , Mathf.Abs (Fighter.transform.position.y - transform.position.y));
        Cathetus = Vector2.Distance(transform.position , Cathetus_End_pos);
        AngleInDeg = Mathf.Cos(Cathetus / Hypotenuse) * Mathf.Rad2Deg;
        Debug.Log("Angle:"+AngleInDeg.ToString());
        Debug.Log("Hypotenuse:" + Hypotenuse.ToString());
        Debug.Log("cathetus:" + Cathetus.ToString());

Assuming your green cathetus in the image is pointing in the world up direction, this will give you the angle between them:

float angle = Vector2.Angle(Vector2.up, (Fighter.transform.position - transform.position));

However I guess what you really want in this case is the signed angle, you can find that like this

Vector2 direction = (Fighter.transform.position - transform.position);
float angle = Vector2.Angle(Vector2.up, direction);
Vector3 cross = Vector3.Cross(Vector2.up, direction);
if (cross.z > 0)
{
    ang = 360 - ang;
}