Problem
The problem I was trying to solve here was to make a system in Unity to display a model and let the user intuitively rotate the model to view it from all angles. I wanted to make sure the user would not get confused as to the viewing angle (ie always know where down was) and also keep the horizon always horizontal on the screen. This also needed to be cross purpose for both desktop and touch mobile.![]() |
Object viewer |
My first attempt was to directly affect the rotational values of the object with click and drag, or touch and drag. This worked great for the first movement, but subsequent actions would alter the viewing angle so that the horizon would not be horizontal. Retracing your steps to get the model to a relatable position was almost impossible.
Solution
The solution I came up with took inspiration from the standard character controller in Unity. I separated the rotations so that the model only rotates around the Y axis, and the camera rotates around the X. I also didn't want the model to be able to rotate upside down, so I added clamp values to the camera's rotation. After a little setup in Unity, I had a solution that met all of my goals, and feels very smooth and intuitive. Download the package below and give it a try!![]() |
Unity setup |
Unity Package: ObjectViewer.UnityPackage