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 ![]()

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());