hi i just started a 2d side scrolling shooter and i have a enemy that has a gun the points a the player. at first i just used LookAt but i wanted to have some dampening in the rotation so i used this code
function Update () {
var target = transform.root.gameObject.GetComponent("AI").target;
var rotate = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * smooth);
}
but i get this weird error ware if i move to close it starts to rotate so that its not in 2d. please help