title: Why does my GameObject returns back to a certain z-position when Joystick is let go?
body: <p>I'm working on a small project in unity. It's a top down game which has a character that is controlled by a joystick. When I run the game, my character starts -90 on the z-position which supposed to be at 0. But when I move the joystick to the direction I wanted it to run it works fine, meaning it's facing the direction where it's running to. However, if I let go of the joystick, the character snaps back to -90 in z-position, which I am trying to figure why it does that and prevent it from happening.</p>
  
  <p>I have looked for tutorial videos and some post in here but none has answered my issue. I also tried removing the "-90f" on my Mathf.Atan2 formula but when I did, it rotates 90 in z-position less. Meaning, when I direct the joystick straight down, the character rotates facing right.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class PlayerController : MonoBehaviour
  {
  
      public static PlayerController instance;
  
      public Rigidbody2D rb;
      public Joystick joystick;
  
      private float moveSpeed = 2.5f;
      Vector2 movement;
  
  
      // Update is called once per frame
      void Update()
      {
          movement.x = joystick.Horizontal;
          movement.y = joystick.Vertical;
      }
  
      void FixedUpdate()
      {
          rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
          float angle = Mathf.Atan2(movement.y, movement.x) * Mathf.Rad2Deg - 90f;
          transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, angle));
      }
  
  </code></pre>
  
  <p>I expect to  have my character to start on 0 in z-position when the game start and also have the character stay and face the direction of the joystick before it was let go instead of rotating back to -90 in z-position.</p>