Question by 
               ThorntonArtStudio · Oct 22, 2015 at 08:22 AM · 
                c#mousedirectionmouseoverrotation detection  
              
 
              Tilt/Rotation based on direction of movement? (player follows mouse hover)
I currently have the following code, which makes the player follow the mouse hover. (player always under mouse)
Before, I was using arrow keys. The line at the bottom made the player tilt in the direction of movement.
However, this tilt rotation doesn't work with mouse hover. I would like the player to tilt/rotate in the direction of movement. Any tips for a beginner?
Thanks!
 using UnityEngine;
 using System.Collections;
 
 public class FollowMouse : MonoBehaviour {
 
     public float distance = 1.0f;
     public float tilt;
 
     // Use this for initialization
     void Start () {
 
     }
 
     // Update is called once per frame
     void Update () {
         Vector3 mousePosition = Input.mousePosition;
         mousePosition.z = distance;
        transform.position = Camera.main.ScreenToWorldPoint(mousePosition);
     }
     void FixedUpdate()
     {
         GetComponent<Rigidbody> ().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody> ().velocity.x * -tilt);
     }
 }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Shooting a bullet towards the mouse 0 Answers
Rotation smoothing 0 Answers
Mouse Active Once Canvas Active, Help! 1 Answer
How do I detect if my mouse is over UI? 0 Answers