using UnityEngine;
using System.Collections;

public class PlayerScript : MonoBehaviour {

    //Game game;
    Rigidbody rb;

    // Use this for initialization
    void Start()
    {
        //game = FindObjectOfType<Game>();	
        rb = GetComponent<Rigidbody>();
    }

    void Movement()
    {
        float speed = 7.5f;
        float xMove = Input.GetAxis("Horizontal") * speed;
        float zMove = Input.GetAxis("Vertical") * speed;

        float rotSpeed = 10;
        float rotTime = 0.00f;
        Vector3 dir = new Vector3(xMove, 0, zMove);

        Vector3 inputDir = (transform.position + dir) - transform.position;
        float rotationStep = rotSpeed * Time.deltaTime;
        Vector3 outputDir = Vector3.RotateTowards(transform.forward, inputDir, rotationStep, rotTime);
        transform.rotation = Quaternion.LookRotation(outputDir);

        if (!(xMove == 0 && zMove == 0))
        {
            rb.velocity = outputDir * speed;
        }
        else
        {
            rb.velocity = Vector3.zero;
        }
    }

    // Update is called once per frame
    void Update()
    {
        Movement();
    }
}
