Tank like Gun Rotate Slowly

Hello!!!
Well, I am making a game were you have a ship and I want the gun of it ot rotate slowly according to the camera’s rotation. I don’t want it to rotate instantly but to see what the camera’s rotation is and then slowly go this rotation.
Anyone have any idea of how to do it?
I’ve search to find any command which does something like this… but found nothing!

this is what i used, not sure if its totally 100 percent but it had worked for me

check out lookrotation and slerp in the docs … you might have to change something there for your usage?

oooh this is for to make the turret face the mouse cursor position
but its a good basis

Slerp makes it slow

what the heck, paste the whole script lol

using UnityEngine;
using System.Collections;

public class TurretScript : MonoBehaviour
{
    public float speed;

    public GameObject projectile;
    public GameObject muzzleFlash;
    public GameObject turretBulletPos;
    public AudioClip tankShoot1;
    
    void FixedUpdate ()
    {
        //Turret Rotation
        Plane playerPlane = new Plane(Vector3.up, transform.position);

        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        float hitdist = 0.0f;

        if (playerPlane.Raycast (ray, out hitdist))
        {
            Vector3 targetPoint = ray.GetPoint(hitdist);
                
            Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed );
        }
    }

    void Update()
    {
        if(Input.GetButtonDown("Fire1"))
        {
            audio.PlayOneShot(tankShoot1);
            Instantiate (muzzleFlash, turretBulletPos.transform.position, transform.rotation);
            Instantiate (projectile, turretBulletPos.transform.position, transform.rotation);
        }
    }


}

I have made a script for the turret to look where the camera looks and actually much smaller… maybe it is because I want only rotation on one axis!

Also, slerp is for rotation and lerp is for everything else, aren’t they?

i guess its just the Slerp line you care about…
i didnt realize my usage of this script was for making the turret face mouse pointer… i pasted it in a hurry before i went to sleep lol

No problem… I did it by using Quaternion.Slerp.
I just set from the rotation the turret already has and to the rotation the camera has. Then I set the rotation to the other axis to 0 since I want rotation on one axis only!
Thinking about it again I may use Mathf.Lerp to do it!:wink:

oh yeah… Lerp should work i guess, if youre rotating it with mouse movement or buttons…

the thing is i had it follow mouse cursor, top view, so when you cross the tank to the other side… like suddenly do a 180, it does a sudden 180 … … i think thats what happened, been a long time, old project … so that needed Slerp