Enemy backing away from player after going around corner?

Hello, right now I am in the final final steps of my game and my last problem I can't seem to fix. Currently I have an enemy that constantly chases the player and when it touches the player it restarts the level, this is all working perfectly right now except that when I go around a corner the enemy then usually starts rotating towards the player but not chasing, and sometimes backing away.

Heres my script:

var target : Transform;
var speed: float;

function Update () {
    if (target == null && GameObject.FindWithTag("Player"))
        target = GameObject.FindWithTag("Player").transform;

    // Rotate towards target    
    var targetPoint = target.position;
    targetPoint.y = transform.position.y;
    var targetRotation = Quaternion.LookRotation (targetPoint -     transform.position, Vector3.up);
    transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2.0);
    transform.Translate (0,0,speed*Time.deltaTime);

function ResetY () {
    transform.rotation.x = 0.0;
    transform.rotation.z = 0.0;
    transform.position.y = 14.5;

Does anyone know why this might be happening? Could adding a raycast and stop chasing when the player is around a corner work?


transform.rotation.x = 0.0;
transform.rotation.z = 0.0;

Rotation is a quaternion. You can't just set values on a quaternion unless you're a Genius. (ha.)


var e = transform.rotation.eulerAngles;
e.x = 0;
e.z = 0;
transform.rotation.eulerAngles = e;