I need help! How do I make that the camera rotates smoothly around the player.

I’ve got a Camera rotating around the player.
The code works fine but I’ve been trying to get the camera to rotate smoothly for days.

Working code without smooth rotation

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotateCamera : MonoBehaviour
{
    public Transform TheCamera;
    public int rotAmount;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            rotAmount += 90;
            TheCamera.localRotation = Quaternion.Euler(TheCamera.localRotation.x, rotAmount, TheCamera.localRotation.z);
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            rotAmount -= 90;
            TheCamera.localRotation = Quaternion.Euler(TheCamera.localRotation.x, rotAmount, TheCamera.localRotation.z);
        }
    }
}

You can use Transform.RotateAround to rotate the camera around a target at a given speed. Put this in your Update or LateUpdate function:

// Spin the camera around the target at 60 degrees/second
transform.RotateAround(target.transform.position, Vector3.up, 60 * Time.deltaTime);

A good explanation for RotateAround is give here.

1 Like

Thank you for your response!

I tried it but it would just rotate camera around 2 degrees on every press. Im sorry if I didn’t give enough info.
The thing is that when you press [Q] the camera will rotate 90 degrees. The camera is attached to a gameobject that is following the player. The code will rotate the gameobject.

nvm I got it working somehow. It has some bugs but when they are fixed I will send the code to this thread. Thank you serhanguel for your help!