- Home /
Toggle between VR and Normal Mode
I have developed a VR game using Unity and Google VR SDK for Android. I want the game to be playable without a VR headset too. How should I implement switching from VR to Normal mode and vice versa? I want to maintain 360 rotation while in Normal Mode using the phone gyroscope. I have looked through many scripts online, but I can't find anything that would make this possible.
I have found that switching modes can be done using XRSettings.enabled = true/false (depending on the mode), but how to maintain 360 rotation while in Normal (Non-VR mode).
Have you seen this? ("unity gyro" google)
It's basically the device's orientation in space, if the 360 rotation you're talking about is around the Y or Up axis, you would probably set your camera/headset? transform's rotation equal to Input.gyro.attitude, followed by setting its X and Z euler angles to zero I guess.
Let me know if I misunderstood the question
@xortrox I tried using Gyro.attitude but I can't get it to work correctly. I want that the rotation before toggling the mode should remain same as that after toggling to normal mode or vice versa and also after toggling to normal mode 360 rotation(head tracking) should be present.
You would basically keep a Quaternion variable for holding "last known" rotations for both normal and XR modes.
At the point where you swap to or from a mode you would stop recording the last known value for the mode you are currently switching from.
example:
/*
This assumes "transform" is your camera or headset object, or whatever object you want to update rotations for when switching modes.
*/
public Quaternion Last$$anonymous$$nownRotXR, Last$$anonymous$$nownRotNormal;
public void EnterXR(){
/*
Quaternions are value types, they will not keep referring to
"transform.rotation" at a later stage
*/
Last$$anonymous$$nownRotNormal = transform.rotation;
XRSettings.enabled = true;
transform.rotation = Last$$anonymous$$nownRotXR;
}
public void ExitXR(){
/*
Quaternions are value types, they will not keep referring to
"transform.rotation" at a later stage
*/
Last$$anonymous$$nownRotXR = transform.rotation;
XRSettings.enabled = false;
transform.rotation = Last$$anonymous$$nownRotNormal;
}