using UnityEngine;
using System.Collections;

public class RotateFacingMovement : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	void FixedUpdate () {
		RotateToFacing();
	}

	private void RotateToFacing()
	{
		Vector2 diff = GetComponent<Rigidbody2D>().velocity;
        if (diff.magnitude == 0)
            return;

		float dx = diff.x;
		float dy = diff.y;
		float aimangle = Mathf.RoundToInt(Mathf.Atan2(dx, dy) * -180/Mathf.PI);
		transform.eulerAngles = new Vector3(0,0,aimangle);
	}
}
