Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
AADProductions's avatar
11 years ago

Best practice for camera rotation offset in Unity 5

I'm working on a game where you spend a lot of time looking down and it's making people a bit uncomfortable. I'd like to add a 45° offset to the camera's x rotation to take the strain off their necks the way 'AaAaaAaaa for the Awesome' did. (Unfortunately I can't rotate the world, it has to be the camera.)

This was pretty straightforward with the Oculus plugin but Unity 5's native VR has made it surprisingly tricky. :|

I've read that Unity doesn't let you change a VR camera's transform. Just for kicks I tried rotating the camera in LateUpdate, OnPreCull and in a coroutine using WaitForEndOfFrame. None worked, so that appears to be true. But I'm not clear on whether Unity has 'locked' the transform or whether Unity just wipes my changes with a later tracking update.

Parenting the camera and rotating the parent transform gets a result. But if the parent's forward doesn't match the camera's forward the horizon gets tilted as you look around. Again just for kicks I tried to fix this by copying the rotation from camera to parent each frame and then zeroing out the camera rotation, but it doesn't work. (And even if it did that seems like a great way to screw up tracking.)

Does anyone know of a best practice for this?

In a perfect world there would be a Monobehavior function that gets called after the tracking is updated, and I'd be allowed to update the camera rotation:

void OnVrTrackingUpdated () {
vrCamera.transform.Rotate (45f, 0f, 0f);//does Unity even permit this?
}

Or heck, while I'm wishing, something you can call on startup would be even cleaner:

UnityEngine.VR.InputTracking.SetLocalRotationOffset (45f, 0f, 0f);

16 Replies

Replies have been turned off for this discussion