Need help smoothing rotation

Hey guys, i need help smoothing my rotation on this script. what it does it rotate my turret towards the enemy and locks the Y axis. what i need is to smooth the turrets rotation, while still locking the axis. How would i use slerp or smoothdamp in this script? Thanks, here’s the script:

Script:

var target : GameObject;
var ToTarget;


function Update () {
	
	target = GameObject.FindGameObjectWithTag("Enemy");
	ToTarget = target.transform.position - gameObject.transform.position;
	ToTarget.y = 0;
	gameObject.transform.forward = ToTarget;
	
}

Unity uses quaternions to calculate rotation. They’re pretty complicated, but there are helper functions to take care of simple tasks.

You might try something like this:

function Update() {
    target = GameObject.FindGameObjectWithTag("Enemy");

    var toTarget : Vector3 = ToTarget = target.transform.position - transform.position;
    toTarget.y = 0;

    var turnRate : float = 100 * Time.deltaTime; //turn 100 degrees per second
    var lookRotation : Quaternion = Quaternion.LookRotation(toTarget);
    transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRotation, turnRate);
}

Script reference pages:

Another option I sometimes prefer is to keep track of a target position (Vector3) which slowly chases after the actual target, then use transform.LookAt() to face that point.