Enemy seems to ignore collisions

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

public class BasicAI : MonoBehaviour {
public Transform target;
public Transform target2;
public Transform myTransform;


void Update () {
  transform.LookAt(target);
  transform.LookAt(target2);
  transform.Translate(Vector3.forward*5*Time.deltaTime);

}
}

This is the code I am using to make an enemy follow the player around, it works well but the enemy goes through walls despite them having collisions.
Does anyone know how to stop this from happening?

There are at least a couple of ways to do this:

  1. Use raycasts (or capsule/box casts) to determine if something is in your path before you move, and act accordingly.
  2. use the physics system to do your movement. This would require you to move with a rigidbody; using its velocity, by adding force to it.

Moving the transform like that does not obey physics interactions like you’re imagining.

Thank you, adding a rigid body fixed my problem.