Here is my humble code, it works but if i stand at zero
PHD degree or close to zero to the object, it choose to rotate full
blasst PHD degree.
Here some more love and hug ===>>>
PHP Code:
void Think_Direction( int entity, float pos_entity[3], float pos_owner[3] )
{
float pos_buff[3];
pos_buff[0] = pos_owner[0];
pos_buff[1] = pos_owner[1];
pos_buff[2] = pos_entity[2]; // we set the pos at same height to please my imagination, noting more.
//SetArray3DFloat( pos_owner[0], pos_owner[1], pos_entity[2], pos_buff );
float ang_entity[3];
float ang_guide[3];
GetEntAngle( entity, ang_entity, 0.0, 0 ); // get the object current world angle
MakeVectorFromPoints( pos_entity, pos_buff, ang_guide );
NormalizeVector( ang_guide, ang_guide );
GetVectorAngles( ang_guide, ang_guide ); // get the world angle between the object and me
float tolerance = 2.0; // we allow this much of angle over shoot/error
float direction = ang_guide[1] - ang_entity[1];
if( direction > (tolerance * -1.0 ) && direction < tolerance ) // dont compare with zero value to rest as we might not catch the exact number
{
direction = 0.0; // tell the object to rest/stop rotate as it reach the nose facing me.
}
// negative value turn right/cw
// positive value turn left/ccw
float force = FORCE_ROTATE * direction;
if( g_fForceDirection[entity] != force )
{
g_fForceDirection[entity] = force;
SetThrusterTorque( g_iPetTroque[entity], force ); // whatever value we get, set it to the rotation force
if( g_fForceDirection[entity] == FORCE_NONE && g_fForceForward[entity] == FORCE_NONE )
{
EmitSoundToAll( SND_TIMEOUT, entity, SNDCHAN_AUTO );
}
}
}
__________________