Hello!
I’ve been having a problem with creating a damping script for my camera’s target. It uses Vector3.SmoothDamp to match the rotation of a car. However, when I turn sharply enough, the camera will sometimes swing around the front of the car to match rotation, instead of towards the back as you would expect. It’s very disorienting and makes the script basically unusable. Any help?
Hierarchy:

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraStablize : MonoBehaviour {
public GameObject car;
public float carX;
public float carY;
public float carZ;
public float damping = 0.1;
private float step;
private Vector3 velocity = Vector3.zero;
void FixedUpdate () {
carX = car.transform.eulerAngles.x;
carY = car.transform.eulerAngles.y;
carZ = car.transform.eulerAngles.z;
transform.eulerAngles = new Vector3(carX - carX, transform.eulerAngles.y, carZ - carZ);
step = damping + Time.deltaTime;
transform.eulerAngles = Vector3.SmoothDamp(transform.eulerAngles, new Vector3(transform.eulerAngles.x, carY, transform.eulerAngles.z), ref velocity, step);
transform.position = car.transform.position;
}
}