title: Rotate around an object to its direction of velocity
body: <p>(For Unity 5.3.5f1)
  Right now I am working on a 3D camera that is orbiting horizontally around the player. The player is a RigidBody rolling sphere. The player can freely rotate the axis horizontally but when there is no input I want the rotation to reset back to the direction of the velocity.</p>
  
  <p>Right now all I need to know is how to situate the camera behind the player's direction of velocity by rotating the camera around the player from its previous rotation.</p>
  
  <p>Here is a crude drawing of what I am looking for:
  <a href="https://i.stack.imgur.com/scA9b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/scA9b.png" alt="enter image description here"></a></p>
  
  <p>Currently to update the camera to orbit around the player I use this script on the camera (with comments):</p>
  
  <pre><code> using UnityEngine;
   using System.Collections;
  
   public class example : MonoBehaviour {
  
       public GameObject Player;
       //I assume you would use this PlayerRB to find data regarding the movement or velocity of the player.
       //public Rigidbody PlayerRB;
  
       private float moveHorizontalCamera;
       private Vector3 offset;
  
       // Use this for initialization
       void Start ()
       {   //the offset of the camera to the player
           offset = new Vector3(Player.transform.position.x - transform.position.x,  transform.position.y - Player.transform.position.y, transform.position.z - Player.transform.position.z);
       }
  
       // Update is called once per frame
       void Update ()
       {
           moveHorizontalCamera = Input.GetAxis("Joy X"); //"Joy X" is my right joystick moving left, none, or right resulting in -1, 0, or 1 respectively
  
           //Copied this part from the web, so I half understand what it does.
           offset = Quaternion.AngleAxis(moveHorizontalCamera, Vector3.up) * offset;
           transform.position = Player.transform.position + offset;
           transform.LookAt(Player.transform.position);
       }
   }
  </code></pre>
  
  <p>Any help at all would be great!</p>