Im going to give you two examples of the same process. Based on yours BTW...
I give you two because the first is to CLEARLY demonstrate how it is working.
The second corrects some shortcomings of the first, but is not so easy to read,
unless you have a basic understanding of the first...
So ... at its most basic, this is a better process to use...
vec_set(vTarget_Temp,your.x);
vec_sub(vTarget_Temp,my.x);
vec_to_angle(vTarget_Angle, vTarget_Temp);
if (ang(vTarget_Angle.x - my.pan + 360)<0)
{
my.pan -= time_step;
}
else if(ang(vTarget_Angle.x - my.pan + 360)>0)
{
my.pan += time_step;
}
It works by calculating the difference between the current pan and the target pan,
then pushing the answer into an area where any POSSIBLE answer is greater than zero,
then uses the ANG() function to turn it back into a 'directional' angle...
Unfortunately, it suffers with 'the jitters' when it (nearly) reaches the target.
Here is an improved version that eliminates the jitters.
vec_set(vTarget_Temp,your.x);
vec_sub(vTarget_Temp,my.x);
vec_to_angle(vTarget_Angle, vTarget_Temp);
var diff = ang(vTarget_Angle.x - my.pan + 360);
if(diff<0)
{
if(abs(diff)>time_step) { my.pan -= time_step; }
else { my.pan -= abs(diff); }
}
else if(diff>0)
{
if(abs(diff)>time_step) { my.pan += time_step; }
else { my.pan += abs(diff); }
}
[EDIT] And after some further thought... If you want to try and decypher a
REALLY compact version of the self-same process that avoids those nasty IF statements,
then try this on for size...
vec_to_angle(vTarget_Angle, vec_sub(vec_set(vTarget_Temp, your.x),my.x));
var diff = ang(vTarget_Angle.x - my.pan + 360);
my.pan += minv(time_step, abs(diff)) * sign(diff);
Enjoy!