title: Jitter when moving around a circular path
body: <p>This is a pretty strange bug. I created the following script intended to calculate positions to shoot projectiles in my game by moving around a circular path and facing the mouse:</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class ProjectileFire : MonoBehaviour
  {
      [System.Serializable]
      public class ButtonDirectionSet {
          public string button;
          public float direction;
          public bool degrees = true;
      }
  
      public GameObject projectile;
      public Vector2 centerPoint;
      public float radius = 1.0f;
      public string fireButton = &quot;Fire1&quot;;
      public bool followMouse = false;
      public bool followKeyboard = true;
      public List&lt;ButtonDirectionSet&gt; buttonDirectionMap = new List&lt;ButtonDirectionSet&gt;();
  
      public bool degrees = true;
      public float direction;
  
      private readonly float maxDirection = 360 * Mathf.Deg2Rad;
  
      // Start is called before the first frame update
      void Start()
      {
          foreach (ButtonDirectionSet set in buttonDirectionMap) {
              if (set.degrees) {
                  set.direction *= Mathf.Deg2Rad;
              }
          }
  
          if (degrees) {
              direction *= Mathf.Deg2Rad;
          }
      }
      void Update()
      {
          foreach (ButtonDirectionSet set in buttonDirectionMap) {
              if (Input.GetButtonDown(set.button)) {
                  direction = set.direction;
              }
          }
  
          if ((followKeyboard &amp;&amp; followMouse &amp;&amp; Input.GetMouseButton(0)) || !followKeyboard) {
              Vector3 mouse = Input.mousePosition;
              mouse.z = transform.position.z - Camera.main.transform.position.z;
              Vector3 mousePosition = transform.InverseTransformPoint(Camera.main.ScreenToWorldPoint(mouse));
  
              float xPos = mousePosition.x - centerPoint.x;
              if (Mathf.Abs(xPos) &lt; 0.1f)
              {
                  xPos = 0.1f * Mathf.Sign(xPos);
              }
              float yPos = mousePosition.y - centerPoint.y;
              if (Mathf.Abs(yPos) &lt; 0.1f)
              {
                  yPos = 0.1f * Mathf.Sign(yPos);
              }
  
              direction = Mathf.Atan2(yPos, xPos);
          }
  
          if (direction &lt; 0) direction += maxDirection;
          transform.localPosition = centerPoint + (new Vector2(Mathf.Cos(direction), Mathf.Sin(direction)) * radius);
      }
  }
  </code></pre>
  <p>If you set both &quot;follow keyboard&quot; and &quot;follow mouse&quot; to true, the object should be positioned toward the mouse when you hold down the left click button. For the most part, this works, but for some reason, there's jitter in the sense that the object rapidly changes between two different positions for a period of time, even when I don't move the mouse at all. Additionally, the &quot;direction&quot; value switches itself at the same rate, even if I don't move my mouse at all. This does not happen all the time, but it does happen pretty frequently at times that appear to be random.</p>
  <p>Is there anything I can do to mitigate or eliminate this behavior?</p>