using UnityEngine;
using System.Collections;

public class SimpleMover : MonoBehaviour {

    public float Speed;
    public bool Wraps = false;

    private Rigidbody2D r2;

	void Start () {
        r2 = GetComponent<Rigidbody2D>();
	}
	
	void FixedUpdate () {
        if (Wraps)
        {
            BoundsHelper.WrapAtBounds(transform);
        }
        else if (!BoundsHelper.BoundsOK(transform, 1))
        {
            GameObject.Destroy(gameObject);
            return;
        }
        
        Vector2 dir = transform.TransformPoint(Vector2.up) - transform.position;
        Vector2 accl = dir * Speed - r2.velocity;
        Vector2 force = r2.mass * accl / Time.fixedDeltaTime;
        r2.AddForce(force);
	}
}
