# Help me about smooth turret rotation

Hi all, I have an exercise about tank turret but i have a broblem.
A can rotate turret horizontal but i can not use Time.deltaTime for smooth rotating (like game World of Tanks.
Here is my code . Thanks all (Sorry my bad English)

``````    public Transform Gun;
public Transform Turret;
public Camera Cam;

Vector3 p =new Vector3(Screen.width/2,Screen.height/2,30f);

void Update()
{

p =Cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,20));

var  targetRotation = Quaternion.LookRotation(p - Turret.position);
Quaternion q =Quaternion.Slerp(transform.rotation,targetRotation,1);
Quaternion TurretQTarget= new Quaternion(0,q.y ,0,q.w) ;
Turret.rotation=TurretQTarget;
}
``````

You have a couple of problems here. I’m uneasy about your direct use of Quaternion() parameters in line 14. Assuming your turret is aligned with Vector3.up (i.e. it’s not attached to some moving ship that can rotate for example), you can solve the rotation problem by modifying ‘p’ before you calculate the look rotation:

``````p.y = Turret.position.y;
``````

You would then remove line 14.

As for your Slerp(), you can do it this way:

``````Quaternion q =Quaternion.Slerp(transform.rotation,targetRotation, speed * Time.deltaTime);
``````

‘speed’ is a variable you define…likely will have a value in the range of 1.0 to 5.0.