using UnityEngine;
using System.Collections;

public class characterMove : MonoBehaviour {

    Rigidbody rbody;
	MeshRenderer mr;
    float speed;
    public float maxSpeed;
	private bool isDeaded;

	// Use this for initialization
	void Start () {
        rbody = gameObject.GetComponent<Rigidbody>();
		speed = maxSpeed;
	}

    void Update()
    {

    }
	
	// Update is called once per frame
	void FixedUpdate () {
            rbody.AddForce((new Vector3(1, 0, 1)) * (Input.GetAxis("Vertical") * speed));
            rbody.AddForce((new Vector3(1, 0, -1)) * (Input.GetAxis("Horizontal") * speed));
		if (isDeaded) {
			rbody.velocity = new Vector3(0,0,0);
		}
        
    }

    void OnCollisionEnter(Collision col)
    {
        if (col.transform.tag == "Ground"){
			speed = maxSpeed;
        }
        if (col.transform.tag == "Kill")
        {
			mr.enabled = false;
			rbody.useGravity = false;
			isDeaded = true;
			Invoke ("onDeath", 3f);
        }
		if (col.transform.tag == "Accel") {
			speed = maxSpeed * 1.5;
		}
    }

    void OnCollisionExit(Collision col)
    {
		if (col.transform.tag == "Accel")
		{
			speed = maxSpeed;
		}
        if (col.transform.tag == "Ground")
        {
			speed = maxSpeed/3;
        }
		
    }

	void onDeath(){ //When character touches "Kill" tag

	}
}
