using UnityEngine;
using System.Collections;

public class PlayerRotate : MonoBehaviour
{


    public float rotateSpeed = 5.0f;

	// Use this for initialization
	void Start () {
	    
	}
	
	// Update is called once per frame
	void FixedUpdate () {
	    Plane playerPlane = new Plane(Vector3.up,transform.position);
	    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

	    float hitDistance = 0.0f;
	    if (playerPlane.Raycast(ray, out hitDistance))
	    {
	        Vector3 targetPoint = ray.GetPoint(hitDistance);
	        Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
	        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotateSpeed*Time.deltaTime);
	    }
	}
}
