how can i smoothly turn an enemy to the player?

i tryed to adjust this code (from the manual) a bit

vec_set(temp,player.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);

i tryed to directly turn..put the vec's in a temp vec and rotate the enemy (my) to the tempvec like this

if(my.pan > my.temp_pan)
{
my.pan -= 5 * time;
}
if(my.pan < my.temp_pan)
{
my.pan += 5 * time;
}

this method works but not without 'bugs'

when the player moves over some certains axis the enemy needs to turn all arround his pan before pans right.

so how to make the enemys pan smoothly without problems ?