Rotation is jumpy

hello everyone
here’s my script:

if(!buScript.around(myTransform.position, this.pos, 0.5f)) {
		int _turn = 0; // left = -1; none = 0; right = 1;
		Vector3 dir = (pos - myTransform.position).normalized;
		float direction = Vector3.Dot(dir, transform.forward);
		if(direction > 0.9f){
			CC.SimpleMove(myTransform.forward * moveSpeed);
			buScript.GoAnimate("walk");
		}else
			buScript.GoAnimate("idle");	
		dir = (pos - myTransform.position).normalized;
		direction = Vector3.Dot(dir, transform.right);

		if(direction > 0.3f) {
			_turn = 1;
		}
		else if(direction < 0.3f) {
			_turn = -1;

		}
		else {
			_turn = 0;
	        }			
	myTransform.Rotate(0, _turn * Time.deltaTime * rotationSpeed, 0);

	}

this is the buScript.around script:

public bool around(Vector3 num, Vector3 around, float prec)
	{
		bool flag = true;
		if(num.x > around.x + prec || num.x < around.x - prec)
			flag = false;
		if(num.y > around.y + prec || num.y < around.y - prec)
			flag = false;
		if(num.z > around.z + prec || num.z < around.z - prec)
			flag = false;
		return flag;
	}

and this is what i get:
1

as you can see the rotation is very jumpy
if you can help me solve it ill be very happy

I guess the problem is the “if-else if-else”. _turn will be 0 only when direction is exactly 0.3. If I understood the logic correctly the “else-if” should be else if(direction < -0.3f)

   if(direction > 0.3f) {
     _turn = 1;
   }
   else if(direction < -0.3f) {
     _turn = -1;

   }
   else {
     _turn = 0;
   }

Try using dot product with the forward vector to determine if you need to rotate and then use the right vector to figure out what direction like:

if (Vector3.Dot(dir, transform.forward) < 0.9f) {
    if (Vector3.Dot(dir, transform.right) >= 0.0f) {
        turn = 1;
    } else {
        turn = -1;
    }
} else {
    turn = 0;
}

Also you can consider using the magnitude of the vector between the object and target’s positions instead of your around function because it will it will describe radial distance whereas the around function basically does a bounding box test as it is. Unless of course this is your intention.