using UnityEngine;

public class Debris : MonoBehaviour {

	public int waveModifier;
	public float speed;

	public float MAX_SPEED_BOOST = 150f;
	public float speedBoost;

	// Use this for initialization
	void Start() {
		waveModifier = 0;
		speed = 0;
		speedBoost = 1;
	}

	// Update is called once per frame
	void Update() {
		transform.Translate(0, 0, (speed + speedBoost) * (waveModifier < 0 ? 0.5f : 1) *  Time.deltaTime);
		transform.position = new Vector3(transform.position.x, 0, transform.position.z);
	}


	void OnTriggerStay(Collider obj) {
		if (obj.tag == "Grav") {
			RotationScript rot = obj.transform.parent.GetComponent<RotationScript>();
			float maxDistance = rot.gravityRadius - rot.planetRadius;
			float myDistanceToCenter = Vector3.Distance(transform.position, obj.transform.parent.position);
			float ratioTowardsOutside = (rot.gravityRadius - myDistanceToCenter) / maxDistance;

			speedBoost = ratioTowardsOutside * MAX_SPEED_BOOST;

		}
	}
}
