help with enemies on slopes

so my enemies are scripted with a box collider, rigidbody, and a script telling them what to do. my script is set so the enemy cannot look vertically, otherwise the enemy would fly into the air if the player jumped, but the x rotation is just modified to face the player.

anyways my problem is that the y rotation wont change, so if the player runs on a slope, the enemies will try to follow but will run straight through the slope and under the ground.

I believe I need to add a character controller to the enemy, but more specifically, what do I need to do in order to fix this, or at least get on the right track?

i found the error. in case anyone else looks here, i simply added a rigidbody with grvity enabled, and set the mass really high so when the enemy gets hit by a bullet they dont go flying off.

You can add this code to the enemy:

var targetDistance;
 var target : Transform;
 var moveSpeed = 8.0;
 var damping = 3.0;

 function Update ()
 {
     targetDistance = Vector3.Distance(target.position, transform.position);

     var offsetDirection = target.position - transform.position;
     offsetDirection.y = 0;
     var rotation = Quaternion.LookRotation(offsetDirection);
     transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
     transform.Translate(offsetDirection.normalized * moveSpeed *Time.deltaTime, Space.World);
 }

It instead of use

transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);

In the last script the enemy allways look at you.meens: if you above him he will look at you and go up to you.

In the first code (the code you need to use) the enemy don't care about your hight and he will never look up or dawn to find you, he just go to the on the same hight he is allways. You don't have to tell the enemy to look at you, the code I gave you will do that so delete the code that tell the enemy to look at you and go to you, and put what I gave you. BTW, the code works with "flying enemies" as well.

The code is in JavaScript so if you use C# I can help you no more.

Sorry for poor english