AI script problem

i have this script so an enemy character moves to a waypoint:

var waypoint : Transform;
var speed :float = 20;
function Update () 
{
    var target : Vector3 = waypoint.position;
    var moveDirection : Vector3 = target - transform.position;

    var velocity = rigidbody.velocity;

    if(moveDirection.magnitude < 1)
    {
        velocity = Vector3.zero;
    }
    else
    {
        velocity = moveDirection.normalized * speed;
    }

    rigidbody.velocity = velocity;
}

it works fine but he the character does not turn to the z axis it just runs along the x axis until it get there. and when it does get there it starts falling threw the ground, and then bounces back up and falls threw again. what is wrong?

Never mind i fixed it:

var waypoint : Transform;
var speed :float = 20;
function Update () 
{    
    var target : Vector3 = waypoint.position;
    var moveDirection : Vector3 = target - transform.position;
    var velocity = rigidbody.velocity;
    if(moveDirection.magnitude < 1)
    {        
velocity = Vector3.zero;
    }
    else
    {
        velocity = moveDirection.normalized * speed;
    }
    rigidbody.velocity = velocity;
    transform.LookAt(target);
}