title: Unity rotate while moving forward
body: <p>I have the following code for my 2D game, it makes object randomly wonder on the screen. What I am having issues with, is when an object looks at the point it is going to, I would like it to rotate as it moves forward. What is happening now, is it rotates instantly to the point it is going towards. So, how can I get it to rotate slowly and move forward at the same time?</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class Wonder : MonoBehaviour {
  
      protected Vector2 wayPoint;
      protected float speed;
  
      // Use this for initialization
      void Start () {
          speed = gameObject.GetComponent&lt;Move&gt;().playerSpeed;
          wonder();
      }
  
      void wonder(){
          wayPoint = Random.insideUnitCircle * 10;
      }
  
      // Update is called once per frame
      void Update () {
          Vector2 dir = wayPoint - new Vector2(transform.position.x, transform.position.y);
          float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
          transform.rotation = Quaternion.Euler(new Vector3(0, 0,Mathf.Atan2 (dir.y, dir.x) * Mathf.Rad2Deg - 90));
          transform.position = Vector2.MoveTowards(transform.position, wayPoint, Time.deltaTime * speed);
          float magnitude = (new Vector2(transform.position.x, transform.position.y) - wayPoint).magnitude;
          if(magnitude &lt; 3){
              wonder();
          }
      }
  }
  </code></pre>
  
  <p>Here is an example Image:</p>
  
  <p><img src="https://i.stack.imgur.com/HuWY6.jpg" alt="Ship Rotation"></p>
  
  <p>So, once the ship gets to its point another will be created and it will move there. I am thinking I will have to have a list of 5+ points, then calculate the arch the ship needs to take adding new points as the ship hits a way point then removing old ones after. I am not sure how to do this though...</p>