Why the control with gyroscope inverted when I make 180 degrees turn?

Dear all

Newbie here…I’ve been developing a clone of Super Monkey ball which you controlled a sphere with character inside with gyroscope. I make the camera always sits behind the character with below script. However every time I make 180 degrees turn, the left, right, up, and down control becomes inverted & if I make another 180 degrees turn, the control will come back normal. Need help how to solve this issue. Thanks.

My CameraFollow script:

using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour {

	public GameObject target;
    public float speed = 5;

    Vector3 offset;

    void Start()
    {
       
                offset = target.transform.position - transform.position;
            
    }

    void LateUpdate()
    {
        
                // Look
                var newRotation = Quaternion.LookRotation(target.transform.position - transform.position);
                transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, speed * Time.deltaTime);

                // Move
                Vector3 newPosition = target.transform.position - target.transform.forward * offset.z - target.transform.up * offset.y;
                transform.position = Vector3.Slerp(transform.position, newPosition, Time.deltaTime * speed);
           
    }
	
}

I’m not sure I follow what’s wrong but looking at your script you’re moving your camera independently to your ball and hoping the ball stays in frame. The two appear to be disconnected. I wrote this script for a car game to make the camera soft follow the car:

    void Update()
    {
        transform.LookAt(Car);
        transform.position = Vector3.SmoothDamp(transform.position, target.position, ref velocity, SmoothTime);
    }

‘Car’ is a public transform which appears in unity. This means you can assign the car (or in your case the ball) to the variable, so in this script ‘Car’ is the position of the car. ‘target’ is another transform which is an empty I attached to the car which is a point behind it where I want the camera to sit. In your case the ball is rotating so this point would rotate with it. So if I were you I would make this a global point behind the ball. just take the transform in the ‘Car’ variable and modify it to get a point behind the ball where you want the camera to sit.