Problems with the script Smooth Follow

Well I added the script Smooth Follow, my camera to follow my character, because the problem is that there are some movements that I do with my character, the camera passes through leaving the ground to see what is inside. I would like to fix it so that when she turned the camera crash into the ground without the cross and did not cease to focus on character

Thx in Advance

One trivial addition to this could be to raycast to the next camera position. If the raycast hit anything, limit the movement to the hit position, and perhaps subtract some length yet to avoid the camera being "exactly on" the ground.

I don't have unity installed at the moment so I can't verify this code would work but basically you'd have two points. One represents the current location and the other represents the next location (that the camera wants to go to);

Vector3 prevPos; // Assume containing interesting data.
Vector3 nextPos; // Assume containing interesting data.
Vector3 deltaPos = nextPos - prevPos;

Vector3 direction = deltaPos.normalized;
float length = deltaPos.magnitude;

RaycastHit hit;
if (Physics.Raycast(prevPos, direction, out hit, length))
    nextPos = prevPos + direction * hit.distance;
    // Or just use nextPos = hit.point..

// Use nextPos that should now "clamp" to the terrain. 
// You probably want to subtract (direction * someAmount),
// to avoid the camera being placed exactly on the terrain.
// Make use of layermasks if you need to fine adjust collision rules.