Forum Discussion
RaveTZ
12 years agoProtege
Maintain Orientation from level to level in Unity?
Every time I load a new level the Oculus treats whatever position I happen to be in as the new center. What is the best way to overcome this? I need Untiy to not reset the camera position every time. I've tried a few ideas, but none of them seem like the best practice.
13 Replies
Replies have been turned off for this discussion
- RavenProtegeI don't have a proper solution, unfortunately. But maybe something in this thread could help: https://developer.oculusvr.com/forums/viewtopic.php?f=37&t=2718
-Hrafn - cyberealityGrand ChampionThis is an interesting question, but I don't think there is a quick fix right now.
- CaliberMengskExplorerBeing that you probably will want to keep your health, and any other scripts you'd have on the player, you could probably just add a don't destroy on load call on the player's awake/start function. http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
This should keep all the orientations proper on the rift as it's not be reloaded. You just need to also set the player's position and rotation manually on level start.
I haven't tried this, but it should work as the OVRController/OVRCamera is never remade, it should keep the same values.
Hope this helps. - RaveTZProtege
"CaliberMengsk" wrote:
Being that you probably will want to keep your health, and any other scripts you'd have on the player, you could probably just add a don't destroy on load call on the player's awake/start function. http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
This should keep all the orientations proper on the rift as it's not be reloaded. You just need to also set the player's position and rotation manually on level start.
I haven't tried this, but it should work as the OVRController/OVRCamera is never remade, it should keep the same values.
Hope this helps.
This is precisely what I ended up doing. I also instantiate the OVRCamera if one isn't present, then move it into position. I will be posting examples for others once they are in a deliverable format. - sh0v0rProtege
"RaveTZ" wrote:
Every time I load a new level the Oculus treats whatever position I happen to be in as the new center. What is the best way to overcome this? I need Untiy to not reset the camera position every time. I've tried a few ideas, but none of them seem like the best practice.
You need to separate out the OVRDevice component and have it persist between scenes by async loading your scenes and ensuring it doesn't get destroyed. This component is what maintains the current state and all CameraControllers reference it.
Alternatively ensure that your OVRCameraController doesn't get destroyed when loading the next scene and there is only ever one of them that is shared with all of your scenes. - CaliberMengskExplorerThe issue with the level async loading is that nothing is ever destroyed. This will create a memory issue after several levels.
That said, it'd be kind of cool to just make one level and have a level culling system (where it unloads things not in the culling area or range of the player) but that's kind of over doing it unless you have an open world or mmo going on.
Best way is still the dontdestroyonload option. - sh0v0rProtege
"CaliberMengsk" wrote:
The issue with the level async loading is that nothing is ever destroyed. This will create a memory issue after several levels.
The way to deal with that is to have a bridging scene that has nothing in it and then call this, it's what I do with Lunar Flight. Most of my high level singletons and managers live in a start up scene that is never destroyed.
http://docs.unity3d.com/Documentation/ScriptReference/Resources.UnloadUnusedAssets.html - vmishraaHonored Guest
"RaveTZ" wrote:
Every time I load a new level the Oculus treats whatever position I happen to be in as the new center. What is the best way to overcome this? I need Untiy to not reset the camera position every time. I've tried a few ideas, but none of them seem like the best practice.
Even I wanted to reset the orientation or the cameras. In my case, I wanted the camera not move at all. I could uncheck the "Enable Orientation", but the orientation wont ever get reset.
This is what I did:
I put a GameObject in the scene, and made a change to the "OVRCamera.cs" file. The function was: SetCameraOrientation()
I searched for the object in the scene. If it existed, I reset the transform and orientation of the camera :
Code:
GameObject obj = GameObject.Find("WhateverObjectNameIs");
if(obj != null)
{
//the camera variable is already defined in the OVRCamera.cs file. YOU DONT HAVE TO DEFINE IT.
camera.transform.position = new Vector3();
camera.transform.rotation = Quaternion.identity;
}
so now you can just make this change depending on how you want to run it. I stopped the orientation completely for one particular level. You can just do it once to reset the Oculus.
Cheers - sh0v0rProtege
"vmishraa" wrote:
"RaveTZ" wrote:
Every time I load a new level the Oculus treats whatever position I happen to be in as the new center. What is the best way to overcome this? I need Untiy to not reset the camera position every time. I've tried a few ideas, but none of them seem like the best practice.
Even I wanted to reset the orientation or the cameras. In my case, I wanted the camera not move at all. I could uncheck the "Enable Orientation", but the orientation wont ever get reset.
This is what I did:
I put a GameObject in the scene, and made a change to the "OVRCamera.cs" file. The function was: SetCameraOrientation()
I searched for the object in the scene. If it existed, I reset the transform and orientation of the camera :
Code:
GameObject obj = GameObject.Find("WhateverObjectNameIs");
if(obj != null)
{
//the camera variable is already defined in the OVRCamera.cs file. YOU DONT HAVE TO DEFINE IT.
camera.transform.position = new Vector3();
camera.transform.rotation = Quaternion.identity;
}
so now you can just make this change depending on how you want to run it. I stopped the orientation completely for one particular level. You can just do it once to reset the Oculus.
Cheers
The OVRController has a check box called 'Reset Tracker on Load' you should uncheck that for subsequent scene loads.
I think the real problem now is that the initial orientation is set when the application starts. If you have your Rift on your face perfectly looking forward its fine but many times its on your desk or lifted up etc...
I think adding a set orientation stage before the game runs would be ideal, I had this before in Lunar Flight with its manual calibration stage but I think I need to at least add back in the Set Orientation. - vmishraaHonored Guest
"sh0v0r" wrote:
I think the real problem now is that the initial orientation is set when the application starts. If you have your Rift on your face perfectly looking forward its fine but many times its on your desk or lifted up etc...
so for this, if you make a tweak as mentioned in my previous post above, which is resetting the orientation of the camera, it would disregard the position/rotation of the Oculus and set the camera to look straight forward(even when the scene loads for the first time).
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 6 months ago
- 3 years ago
- 2 months ago