Smooth and restrict rotations?

I’m Stuck!! How do I correctly lock the z axis so it cannot rotate, and how can I get the rotations to be smoother (less sensitive)? Thanks a bunch for any help!

var howMuch = .1;
var speed = 8;
private var yRotationOffset : float = 0;

function Update () {
    var controller : CharacterController = GetComponent(CharacterController);
    var hit : RaycastHit;
    var castPos = Vector3(transform.position.x,transform.position.y- howMuch,transform.position.z);
    if (controller.isGrounded)
    {
        if (Physics.Raycast (castPos, -transform.up, hit)) {
            transform.up = hit.normal; //direction
            transform.Rotate (0, yRotationOffset, 0); //Apply y-rotation offset.
        }else{
            // If we're not aligning the player, we can apply the rotation directly
            transform.Rotate (0, Input.GetAxis ("Horizontal"), 0); 
        }
        yRotationOffset += Input.GetAxis ("Horizontal") * speed;
        if (!controller.isGrounded){
            transform.rotation.z = 0;
            transform.rotation.x =0;
        }
    }//if (controller.isGrounded)
}//update()

You can try using the “lerp” function to get smoother rotations, and setting rotation.x to zero fixes the rotation problem right? Check here for a reference on all kinds of “lerp” functions.

Here is how you would “lerp” angles:

var minAngle = 0.0;
var maxAngle = 90.0;

function Update () {
    //Time.time is one second. Change that to any time you want
    var angle : float = Mathf.LerpAngle(minAngle, maxAngle, Time.time);
    transform.eulerAngles = Vector3(0, angle, 0);
}

And here is how you would “lerp” a vector3:

var objPos : transform.position;
var endPos : Vector3(0,0,0);

function Update () {
    //Time.time is one second. Change that to any time you want
    transform.position = Vector3.Lerp(objPos, endPos, Time.time);
}