using UnityEngine;

public class Ball : MonoBehaviour
{
	Rigidbody rb;

	void Awake()
	{
		rb = GetComponent<Rigidbody>();
	}

	void FixedUpdate()
	{
		var pos = rb.position;

		if(pos.x > 3.5f)
		{
			var disp = 3.5f - pos.x;
			rb.AddForce(disp * 20, 0, 0);
		}
		else if(pos.x < -3.5f)
		{
			var disp = -3.5f - pos.x;
			rb.AddForce(disp * 20, 0, 0);
		}
	}

	public void Reset()
	{
		rb.MovePosition(Vector3.up * 2.5f);
		rb.velocity = Vector3.zero;
	}
}