﻿using UnityEngine;
using System.Collections;

public class BoundaryScript : MonoBehaviour {

	private float fNewXVelocity, fNewZVelocity;

	void OnTriggerExit(Collider other) {

		do {
			fNewXVelocity = other.GetComponent<Rigidbody>().velocity.x * Random.Range (-.5f, -1.5f);
		} while(Mathf.Abs(fNewXVelocity) < 2  || Mathf.Abs(fNewXVelocity) > 10) ;

		do{
			fNewZVelocity  = other.GetComponent<Rigidbody>().velocity.z * Random.Range (-.5f, -1.5f);
		} while(Mathf.Abs(fNewZVelocity) < 2  || Mathf.Abs(fNewXVelocity) > 10) ;

//		fNewXVelocity = Random.Range (-5.0f, 5.0f);
//		fNewZVelocity = Random.Range (-5.0f, 5.0f);

		other.GetComponent<Rigidbody>().velocity = new Vector3 (fNewXVelocity, .0f, fNewZVelocity) ;

	}
}
