I am currently trying to make something fly with Oculus Rift.
The only control is the Oculus Camera.
The player is always moving forward, but I want to allow him to rotate, go up, and down. To go up, the player must look at 10° to 45° up, same for all directions.
I'm currently using Unity, and I get a quaternion about the camera rotation.
Is there any script doing it? How can I do it myself, or at least, how can I translate quaternion to rotation?
Good news! For your purposes you won't need to deal directly with quaternions. A little vector math might help, though.
transform.forward
in any script will give you the forward direction of the object the script is attached to. If it's on the camera, it will be the direction the player is looking.
Using just the camera's forward direction, and the forward direction the player moves along, you can calculate the needed information for your player rotation.
Vector3.Angle(transform.forward, cameraObject.transform.forward)
will give you the angle between the two forward directions.
Vector3.Cross(transform.forward, cameraObject.transform.forward)
will give you the axis of rotation.
You can check if the angle is within the desired range, and use
transform.Rotate(Vector3.Cross(transform.forward, cameraObject.transform.forward), rotationSpeed * Time.deltaTime)
to perform the rotation. If the rotation is in the opposite direction than what you want, you might need to switch the order of the two parameters to Vector3.Cross
.