Camera Quaternion.RotateTowards without rolling/banking
I have a camera facing the ground and I want to pan up to look at a target object in the distance.
Currently, I achieve this with the following:
Vector3 dir = targetPoint - transform.position;
Quaternion lookRotation = Quaternion.LookRotation(dir);
Quaternion newRotation = Quaternion.RotateTowards(transform.rotation, lookRotation, rotationDamping * Time.deltaTime);
transform.rotation = newRotation;
The camera performs the rotation and ends up pointing at the target object correctly, but as the camera pans up it tilts to one side making my game world set at an angle to the viewer, which is pretty disorienting:
How can I constrain the camera angle some way so that the horizon is always flat to the camera?
Thanks!
Answer by bbeckford · Aug 24, 2017 at 02:27 PM
After getting no response here I then asked the question on Stack Overflow instead and got this answer - https://stackoverflow.com/questions/45786183/unity-camera-quaternion-rotatetowards-without-rolling-banking/45846425#45846425
Just thought it might help others searching.
Your answer
Follow this Question
Related Questions
I cannot move my camera in the Game mode 0 Answers
Pivot Camera to Follow Mouse Position? 0 Answers
Rotate ball in camera's direction.... 0 Answers