Look at mouse cursor without flipping

I have this script:

var lookTarget : Vector3;

function Update() {
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    var hit : RaycastHit;
    if (Physics.Raycast (ray, hit)){
        lookTarget = hit.point;
	}
    transform.LookAt(lookTarget);
}

I have it attached to my player but when I move the cursor closer to my player it will flip around. How do I fix this?

It is possible that your Raycast hit Y-axis is lower than your character Y-axis. Try this (untested):

lookTarget = Vector3(hit.point.x, transform.position.y, hit.point.z);