Enemy AI Issues!!?!

My AI is being stubborn and I was wondering if their is a quick fix to my problem… I have a box colliders on everything from walls to player to AI, but for some reason my Enemy wants to faze through walls, and keeps pushing my character when it’s shouldn’t… i was wondering if their is a quick fix to this problem I provided the script and a picture of the problem… “NO Error in script”

*I want my enemy to stop at a distance of .25 away from player… I want my enemy to avoid and not go through walls…

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(SphereCollider))]
public class EnemyAI : MonoBehaviour {

    public float preceptionRadius = 10;

    public Transform target;
    public float movementSpeed = 5;
    public float rotationSpeed = 420;

    private Transform myTransform;

	// Use this for initialization
	void Start ()
    {
        SphereCollider sc = GetComponent<SphereCollider>();
        CharacterController cc = GetComponent<CharacterController>();

        if (sc == null)
            Debug.LogError("No Collider on enemy");
        else
        {
            sc.isTrigger = true;
        }

        if(cc == null)
        {
            Debug.LogError("There's no Character Controller");
        }
        else
        {
            sc.center = cc.center;
            sc.radius = preceptionRadius;
        }

        myTransform = transform;
	}

    // Update is called once per frame
    void Update()
    {
        if (target)
        {
            Vector3 dir = (target.position - myTransform.position).normalized;
            float direction = Vector3.Dot(dir, transform.forward);

            float dist = Vector3.Distance(target.position, myTransform.position);

            //Find or Look at Target
            myTransform.rotation = Quaternion.Lerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);

            //Movement
            myTransform.position += myTransform.forward * movementSpeed * Time.deltaTime;
        }
    }

    public void OnTriggerEnter(Collider other)
    {
        Debug.Log("Entered");
        if (other.CompareTag("Player"))
        {
            target = other.transform;
        }
    }
    public void OnTriggerExit(Collider other)
    {
        Debug.Log("Exit");
        if(other.CompareTag("Player"))
        {
            target = null;
        }
    }
}

Enemy is black player is red…

to make the enemy stop moving when he hits the player i would use line cast and then make a bool moveTorwardsPlayer and set the bool to true if the player is not in the line cast and the same for the wall just if walls are not in the line cast

some Documentation [Unity - Scripting API: Physics.Linecast][1]

Example

public bool moveTorwardsPlayer;
public LayerMask MoveBlockers;

public Void FixedUpdate()
{
   moveTorwardsPlayer = Physic2D.linecast("FirstPoint.poistion","SecoundPoint", MoveBlockers );
}

public Void Update()
{
   if (moveTorwardsPlayer)
{
   // Do ai stuff
}
}

this is untested code but it should give you the idea of what to do
hope this helps :slight_smile: