Currently i have a basic enemy follow script but he gets caught on walls and such in my 2D topdown game and i wanted to make him check for collision but im not exactly sure how to do this here is my
public class EnemyFollow : MonoBehaviour
{
public float speed;
private Transform target;
private void OnTriggerStay2D(Collider2D collision)
{
{
if (Vector2.Distance(transform.position, target.position) > 1.0)
{
transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
}
}
}
// Use this for initialization
void Start()
{
target = GameObject.FindGameObjectWithTag("Player").GetComponent();
}
↧