using UnityEngine;
using System.Collections;

public class Entity : MonoBehaviour {

	public Rigidbody body;

	public void Awake() {
		body = GetComponent<Rigidbody> ();
	}

	public void setLoc(Vector2 loc) {
		transform.position = new Vector3 (loc.x, 0.0f, loc.y);
	}

	public Vector2 getLoc() {
		return new Vector2(transform.position.x, transform.position.z);
	}

	public Vector2 getVelocity() {
		return new Vector2 (body.velocity.x, body.velocity.z);
	}

	public void fixYAxis() {

		// update our y-axis by doing a raycast for terrain
		Ray ray = new Ray (transform.position + new Vector3(0, 500, 0), new Vector3(0, -1, 0));
		RaycastHit hitInfo;
		if (Physics.Raycast (ray, out hitInfo, float.MaxValue, 1 << 9)) {

			// 
			transform.position = new Vector3(transform.position.x, hitInfo.point.y + transform.localScale.y / 2.0f, transform.position.z);
		}
	}
}
