void Movement(Entity target, float distance) { animator.SetFloat("Speed", Mathf.Abs(distance)); //collision detection asdf = new Collider2D[10]; int i = c2d.OverlapCollider(contactFilter, asdf); if (i > 0) { rb2d.velocity = new Vector2(0, 0); // stop walking, too close foreach (Collider2D col in asdf) { if (col != null) // if there is a collision { //if (col.gameObject.tag.Equals("Player")) //Debug.Log("companion is touching player"); //if (col.gameObject.tag.Equals("Enemy")) //Debug.Log("companion is touching enemy"); if (col.gameObject.GetComponent <Entity>() == target && target != p) { c.Combat(col.gameObject.GetComponent <Entity>()); return; } } } } Move(target, distance); }