Camera to follow & ROTATE with Sphere?

Hi all,

Please forgive my ignorance… brand new to Unity and trying to create my first project. Am creating a role-a-ball maze which is coming along nicely except for one issue I just cannot remedy, despite spending 3 days trying, following tutorials etc…

I have a simple Player Controller Script for movement and a Camera Controller that is following a sphere. The camera is not a child of the sphere to prevent the camera spinning around the x axis when the sphere rolls forwards or backwards.

I am trying to work out how to make the camera rotate around the sphere when ever the player turns left or right, so that the camera is always behind the sphere and then forwards becomes the new direction the camera is facing, much like in a 1st person view - but again, not sure how to do this without making the camera a child of the player, which again will make it spin!!!

Is there something simple I am missing to stop the camera spinning when I make it a child of the sphere?

OR

Is there some coding I can add to the below script to rotate the camera as the sphere turns?

Current Camera Controller:

using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
void Start()
{
offset = transform.position - player.transform.position;
}

void LateUpdate()
{
transform.position = player.transform.position + offset;
}
}

Any help, would be greatly appreciated from a newbie…

Thanks.

use ‘code’ tags (with square brackets) to format the code properly

try adding your camera to belong to sphere’s transform (like you do in the hierarchy panel)

camera.transform.SetParent(sphere.transform);