# RotateAround source code

Hey there.

I have the following source code:

``````public override IEnumerator transformPlayer(MyTransform target, GameObject selection)
{
yield return new WaitForFixedUpdate();
Vector3 around = SelectionScript.Selection.transform.position;
Vector3 to = target.Position - around;
Vector3 from = gg.Player.Position - around;
Quaternion oRot = gg.Player.Rotation;
int totalDeg = Mathf.RoundToInt(Mathf.Abs(Mathf.Acos(Vector2.Dot(((Vector2)to).normalized, ((Vector2)from).normalized))) / Mathf.PI * 180);
float total = totalDeg / 180.0f * Mathf.PI;
int mul = GraphicsCore.IsLeftTo(to, from, Vector3.forward) ? 1 : -1;
float angle = 0;
float v = 0;

do
{

angle = Mathf.SmoothDampAngle(angle, total, ref v, 0.33f);
Quaternion absRot = Quaternion.AngleAxis(angle / Mathf.PI * 180 * mul, Vector3.forward);
gg.Player.Rotation = oRot * absRot;
gg.Player.Position = absRot * from + around;
yield return null;
} while ((total - angle) > 0.01f);

gg.Player.Position = target.Position;
gg.Player.Rotation = target.Rotation;
}
``````

This was my own implementation for smoothly rotating a game object around a given point. The problem with this, is that the game object experiences a little bit of jitter, which is more pronounced around the slower end of the animation. By jitter I mean the gameobject seems to make tiny tiny little shakings in random directions which is only noticeable if you pay close attention to the animation. Otherwise, it looks like a perfect rotation.

However, when I modified my code to use the built in `Transform.RotateAround(point, axis, angle)` function, I experienced ZERO jitter which was quite surprising. For fun fact, I also tried using `Quaternion.Slerp` but it did not make difference.

My code with RotateAround is:

``````public override IEnumerator transformPlayer(MyTransform target, GameObject selection)
{
yield return new WaitForFixedUpdate();
Vector3 around = SelectionScript.Selection.transform.position;
Vector3 to = target.Position - around;
Vector3 from = gg.Player.Position - around;
// Quaternion oRot = gg.Player.Rotation;
int totalDeg = Mathf.RoundToInt(Mathf.Abs(Mathf.Acos(Vector2.Dot(((Vector2)to).normalized, ((Vector2)from).normalized))) / Mathf.PI * 180);
float total = totalDeg / 180.0f * Mathf.PI;
int mul = GraphicsCore.IsLeftTo(to, from, Vector3.forward) ? 1 : -1;
float angle = 0;
float v = 0;
float prev = 0;

do
{

angle = Mathf.SmoothDampAngle(angle, total, ref v, 0.33f);
/*Quaternion absRot = Quaternion.AngleAxis(angle / Mathf.PI * 180 * mul, Vector3.forward);
gg.Player.Rotation = oRot * absRot;
gg.Player.Position = absRot * from + around;*/
gg.Player.transform.RotateAround(around, Vector3.forward, (angle - prev) * mul / Mathf.PI * 180);
prev = angle;
yield return null;
} while ((total - angle) > 0.01f);

gg.Player.Position = target.Position;
gg.Player.Rotation = target.Rotation;
}
``````

I can not figure out what this code does differently from how I make the rotation. I tried performing the animation by applying tiny angle rotations relative to the current position, and NOT relative to the original position, but it actually made it worse instead of better.

What am I doing wrong? What does RotateAround do to eliminate the jitter?