Make the camera rotate around the player and face the player.

Hey guys!

I’m pretty new to coding, and the game I’m making needs to have the camera controlled by the mouse. What I want the camera to do is to rotate (or orbit) around the character when I move the mouse left or right. The camera doesn’t have to turn the player, they are independent of one and other. I just want the camera to follow the player and orbit around when the mouse is moved.

Thank you!

I’m using this on my game-in -development and it seems to work, if you’re using an XBox controller.
Not sure why all of the code didn’t make it into the one window below but be sure to include the public or SerializeField variables at the top. It worked like a charm for me.
**also…I’m using the Input Manager Package so you’ll need to download that to your project as well.

-Chaun

public class FollowCamera : MonoBehaviour
{
[SerializeField] GameObject player;
[SerializeField] float OrbitDegrees = 100f;

Vector3 _offset;

void Start()
{
    _offset = (transform.position - player.transform.position);
}

void Update()
{
    var gamepad = Gamepad.current;
    if (gamepad == null)
        return;
    else
    CameraOrbitControl(gamepad);
}

void CameraOrbitControl(Gamepad gamepad)
{
    Vector3 move = gamepad.rightStick.ReadValue();
    transform.RotateAround(player.transform.position, Vector3.up, OrbitDegrees * move.x);
}