Forum Discussion
bdeschryver
12 years agoExplorer
Reset Rift yaw when game starts
Hey Unity users,
I am building a demo of a (virtual) scene to experience while being sit on a chair with the Rift.
When my Unity software starts, the screen is all black so that no image is displayed during the time I am giving the Rift to the participant for the demo. He has time to put the Rift on his head and when he is ready, I am pressing a key and the virtual world fades in on the screen.
The problem with this is that when I start my software, it uses the Rift yaw value at that moment for the 'forward' direction of the camera. If then I pass the Rift the someone who puts it on but is not oriented as the Rift was when my software started, he will see the virtual world has he had already rotated...
I need to make sure that no matter what the current Rift yaw value is, when I press the key to start displaying my virtual world on the screen, it should be 'reset' so that the camera direction will be straight forward. This way I can press the key when the guy is looking straight in front of him and make sure he sees what I want him to see at startup.
Any idea how to do that ? I know in the Oculus demos, a key is used to reset the sensor data. In my case only the yaw is needed.
I tought InitializeInputs or SetCameras from OVRPlayerController would do that but it does not help...
Thanks !
I am building a demo of a (virtual) scene to experience while being sit on a chair with the Rift.
When my Unity software starts, the screen is all black so that no image is displayed during the time I am giving the Rift to the participant for the demo. He has time to put the Rift on his head and when he is ready, I am pressing a key and the virtual world fades in on the screen.
The problem with this is that when I start my software, it uses the Rift yaw value at that moment for the 'forward' direction of the camera. If then I pass the Rift the someone who puts it on but is not oriented as the Rift was when my software started, he will see the virtual world has he had already rotated...
I need to make sure that no matter what the current Rift yaw value is, when I press the key to start displaying my virtual world on the screen, it should be 'reset' so that the camera direction will be straight forward. This way I can press the key when the guy is looking straight in front of him and make sure he sees what I want him to see at startup.
Any idea how to do that ? I know in the Oculus demos, a key is used to reset the sensor data. In my case only the yaw is needed.
I tought InitializeInputs or SetCameras from OVRPlayerController would do that but it does not help...
Thanks !
14 Replies
Replies have been turned off for this discussion
- cyberealityGrand ChampionYou can use the following:
OVRDevice.ResetOrientation(0);
- bdeschryverExplorerthank you for your asnwer Cyberreality.
I am trying to use this from a script attached to the OVRPlayerController, using this command:
GetComponentInChildren<OVRDevice>().SendMessage ("ResetOrientation",0);
but I am getting an error of "SendMessage ResetOrientation has no receiver".
Would you know why ?
Thank you ! - raidho36ExplorerYou can just call it directly from pretty much anywhere.
GameObject.Find("OVRCameraController").GetComponent<OVRDevice>().ResetOrientation(0); - bdeschryverExplorerthanks ! I'll try that asap !
- bdeschryverExplorerraidho36,
I tried your code but it does not work, as ResetOrientation is a static function.
I went around this by adding my own non-static function in OVR device script which in turns calls the official ResetOrientation.
Can you confirm this ?
Thanks again ! - raidho36ExplorerI just popped out that out of my head so I forgot it was static.
What you actually do is just directly invoke the function, exactly like cyberreality posted it. - philedayMemberI'm still having trouble with this. I using Javascript and use this code:
GameObject.Find("OVRCameraController").OVRDevice.ResetOrientation(0);
and get this error
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
Player Script.Update () (at Assets/Scripts/Player Script.js:350)
Any help would be great appreciated.
Phil - bdeschryverExplorerI don't know if this applies to you in Javascript, but you can't call the function ResetOrientation like you do because then you are trying to use it on a specific instance (the gameboject you are finding with GameObject.Find("OVRCameraController")).
As it is a static function, you can call it only from inside the class itslef.
My solution was to add in the OVRDevice class a non-static function called ResetOrientation2 which calls ResetOrientation(0) directly.
Someone corrects me if I am wrong... - philedayMemberI'm not sure how classes are dealt with in Java. I'm relatively new to unity so I'm still learning.
Ultamitly what I'm hopeing to achive is when the user hits a key the orientation is reset. It doesn't have to be part of another script or attached to a curtain object or in Javascript just as long as the player can hit say "R" at any point of the game and the orientation is reset.
An example of a complete script with wrong code is provided below.
------------------------------------------------------------------------------------------------------------
#pragma strict
function Start () {
}
function Update () {
if ((Input.GetButtonDown ("Fire1"))){
GameObject.Find("OVRCameraController").OVRDevice.ResetOrientation(0); (Wrong code)
}
}
----------------------------------------------------------------------------------------------------------
As I mentioned it doesn't even have to be in Java.
Hopefully that might make it easier to give me advice on how to apply this. If i come up with an answer with my research I'll also post it here so if you having trouble yourself keep checking back.
Cheers. - bdeschryverExplorerI was trying to do the same exact thing and it works if you do it like I described in my last message.
When hitting a key, trigger a non static function that you add to the OVRDevice class. This function will call the static one.
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
- 5 years ago
- 3 years ago
- 2 years ago
- 5 years ago