Following Script Not Working Properly

Hey guys, i have a problem with my script here, the script works but when the enemy follows me it keeps descending with as result going trough the terrain (putting the model higher doesn’t work) other then that the script works perfectly fine. Thanks in advance.

The Script:

#pragma strict

function Start () {


//target to follow 
var target : Transform;

//Checks his position
var pos : Transform;

//Ray variables
var rayLength : float = 3;

var speed : float = 4;

 var move : boolean = false;

function FixedUpdate() {


function Update() {
var fwd = transform.TransformDirection (Vector3.forward); var hit : RaycastHit;

    if (renderer.isVisible)
    move = false;

    move = true;

    //Follows meh i don't watch him
    //Look at target
    //Follow meh
    pos.position += pos.forward * speed * Time.deltaTime;

    //Temp avoidance
    if (Physics.Raycast (transform.position, fwd,rayLength)
&& move)
    transform.Translate(Vector3.right * 3 * Time.deltaTime);


I think i fixed it by adding a Box collider with Rigidbody and enabling gravity. There are no worries now as in the game he won’t be going over steep things.