using UnityEngine;
using System.Collections;

public class CharControl : MonoBehaviour {
	float speed = 80.0f;
	float gravity = 100.0f;
	private Vector3 moveDirection = Vector3.zero;
	private bool grounded = false;

	void FixedUpdate() {

		if (grounded) {
			moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
			
			moveDirection = transform.TransformDirection(moveDirection);
			moveDirection *= speed;
			
			
		}
		moveDirection.y -= gravity * Time.deltaTime;
		CharacterController controller = gameObject.GetComponent(typeof(CharacterController)) as CharacterController;
		CollisionFlags flags = controller.Move(moveDirection * Time.deltaTime);
		grounded = (flags & CollisionFlags.CollidedBelow) != 0;
	}
}