I'm using this homebrew function I made about a year ago:

C++:

```
float DifferenceOfAngles(vec3_t src, vec3_t dst)
{
vec3_t diff;
diff.y = src.y - dst.y;
diff.x = src.x - dst.x;
//normalize by making them positive values if they are negative
if (diff.y < 0)
{
diff.y *= -1;
}
if (diff.x < 0)
{
diff.x *= -1;
}
//add them together and divide by 2, gives an average of the 2 angles
float fDifference = (diff.y + diff.x) / 2;
return fDifference;
}
```

I thought you could subtract the vectors and divide the resulting vector by the magnitude to normalize the angle, this works to some degree but same issue, when the enemy is behind you the calculation isn't 100% perfect.

Function definitions:

C++:

```
vec3_t Subtract(vec3_t src, vec3_t dst)
{
vec3_t diff;
diff.x = src.x - dst.x;
diff.y = src.y - dst.y;
diff.z = src.z - dst.z;
return diff;
}
vec3_t Divide(vec3_t src, float num)
{
vec3_t vec;
vec.x = src.x / num;
vec.y = src.y / num;
vec.z = src.z / num;
return vec;
}
float Magnitude(vec3_t vec)
{
return sqrtf(vec.x*vec.x + vec.y*vec.y + vec.z*vec.z);
}
vec3_t Normalize(vec3_t src)
{
vec3_t vec = Divide(src, Magnitude(src));
return vec;
}
```

C++:

```
vec3_t angleDiff = Subtract(localPlayer.angle, angleToEnemy);
float diff = Normalize(angleDiff);
```

I believe this is because the discrepancy between one angle being based on ~360 and the other angle being based on ~180.

Writing 2 seperate normalize functions would be the solution?

By adding 360 and 180 respectively to the angles?