My camera orbits around an object. The LookAt function changes all x,y and z axis values at 90 degrees and 270 degrees. I want a smooth view but the camera flips suddenly. How can I solve this problem? (I’m in space. There is no up or down.)
My code is like this:
public Vector3 DistanceVector = Vector3.zero;
public float Distance = 5f;
void Update()
{
// get object to camera vector
DistanceVector = transform.position - Target.position;
if (Input.GetMouseButton(1))
{
//rotate camera
DistanceVector = Quaternion.Euler(5f, 0, 0) * DistanceVector;
}
// move camera to calculated position
DistanceVector = DistanceVector / DistanceVector.magnitude * Distance;
transform.position = Target.position + DistanceVector;
// look at the object
transform.LookAt(Target);
}
