using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour {

    public float movementSpeed = 1;
    public float strafeSpeed = 0.5f;
    public float turnSpeed = 1;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        var rotation = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
        transform.Rotate(Vector3.up, rotation);

        var movementVector = new Vector3();
        movementVector.z += Input.GetAxis("Vertical") * movementSpeed * Time.deltaTime;
        movementVector.x += Input.GetAxis("Diagonal") * strafeSpeed * Time.deltaTime;
        movementVector = transform.rotation * movementVector;
        transform.position += movementVector;

        var allowedRadius = Game.zone.radius;

        var distance = Vector3.Magnitude(transform.position);
        if (distance > allowedRadius)
        {
            Game.hints.ShowError("Do not travel too far until you've gained in strength");
            transform.position -= transform.position / distance;
        }
	}
}
