using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AvoidScript : MonoBehaviour {



    void OnTriggerEnter2D(Collider2D collider)
    {
        //print("jee");
        if (collider.gameObject.layer == LayerMask.NameToLayer("enemy"))
        {
            if (transform.parent.GetComponent<Rigidbody2D>().velocity.magnitude > 1) return;
            transform.parent.GetComponent<Rigidbody2D>().velocity += (Vector2)(transform.position - collider.transform.position).normalized*0.1f;
                //.AddForce((transform.position - collider.transform.position).normalized*200);
            //print("avoiding");
        }
    }
}
