Finding direction of head rotation when camera is fixed

I’m developing a Google Cardboard app with Unity where an object floating in the scene can be rotated in certain fixed directions by rotating one’s head. The idea is that the user can only rotate the object left/right/up/down (y-axis or x-axis), one direction at a time, by facing the corresponding direction. Upon facing that direction, the object rotates slowly, and only stops rotating if the user returns to face the center.

Using GvrViewer, I can get the Quaternion and the difference in angle from the center. However, I don’t know where to begin to get the general direction the user is facing in order to compute what axis to rotate the object around.

Add a transform to your scene with forward pointed in the “starting” direction of your camera. As the user rotates the camera dot the camera.transform.forward/up/right with your controls transform.forward/up/right and compare them.

1 Like