Search Unity

Switching VR Camera's = double initial Rotation value

Discussion in 'AR/VR (XR) Discussion' started by tbr, Sep 26, 2016.

  1. tbr

    tbr

    Joined:
    Oct 23, 2015
    Posts:
    10
    I have a strange problem when I try and swap OVRCamera's in Unity. I'm currently using Unity 5.4.1f1 and the latest ovr_unity_utilities_1.8.0.

    I have edited the MultiCam script from the OculusSampleFrameworkProject_1.5.0 to allow me to swap between OVRPlayerControllers instead of OVRCameraRigs. It's set up to swap on a button press from the controller (for testing) and when the player collides with a trigger object, or when a player presses a button (using Gaze Pointer).

    Anyway the issue I have is that whenever I switch to my second OVRPlayerController the initial rotation of the X and Z axis seem to be doubled so to the user the world is tilted.

    For example if I leave my Oculus headset on the desk and look at the CenterEyeAnchor rotation settings for the first OVRPlayerController it may show X=-6 y=0 z=-0.1 wheras when I switch to the second OVRPlayerController the figures are x=-12 y=0 z=-0.2

    I can't see why this would be the case?

    The script is below.

    Code (CSharp):
    1.  using UnityEngine;
    2. public class MultiCameraSetup : MonoBehaviour {
    3.      public OVRPlayerController[] playerControllers = new OVRPlayerController[0];
    4.      public Transform[] rayTransformControllers = new Transform[0];
    5.      public int                currentController = 0;
    6.      public OVRInput.RawButton forwardButton = OVRInput.RawButton.Y;
    7.      public OVRInput.RawButton backwardButton = OVRInput.RawButton.X;
    8.      public static bool doIStart = false;
    9.      void Start() {
    10.          UpdateCameraControllers();
    11.          UpdateRayTransformControllers ();
    12.      }
    13.      public static void SwapBool() {
    14.          if (doIStart == false) {
    15.              doIStart = true;
    16.              Debug.Log ("Bool Switched");
    17.          }
    18.      }
    19.      void UpdateCameraControllers() {
    20.          for (int i = 0; i < playerControllers.Length; i++) {
    21.              if (playerControllers [i] == null) {
    22.                  continue;
    23.              }
    24.              playerControllers [i].gameObject.SetActive (i == currentController);
    25.              OVRManager.display.RecenterPose();
    26.          }
    27.      }
    28.      void UpdateRayTransformControllers() {
    29.              for ( int i = 0; i < rayTransformControllers.Length; i++ ) {
    30.                  if ( rayTransformControllers[i] == null ) {
    31.                      continue;
    32.                  }
    33.              RayTransforms.mainRayTransform = rayTransformControllers [i];
    34.              }
    35.          OVRGazePointer.instance.Awake();
    36.      }
    37.      void Update() {
    38.        
    39.          if (doIStart == true){
    40.              doIStart = false;
    41.              Debug.Log("Glowring Activated");
    42.              SwapCameras ();
    43.          }
    44.          if ( OVRInput.GetDown(forwardButton)) {
    45.              if ( ++currentController == playerControllers.Length ) {
    46.                  currentController = 0;
    47.              }
    48.              UpdateCameraControllers();
    49.              UpdateRayTransformControllers ();
    50.          } else if ( OVRInput.GetDown(backwardButton)) {
    51.              if ( --currentController < 0 ) {
    52.                  currentController = playerControllers.Length - 1;
    53.              }
    54.              UpdateCameraControllers();
    55.              UpdateRayTransformControllers ();
    56.          }
    57.      }
    58.      void SwapCameras ()
    59.      {
    60.          if ( ++currentController == playerControllers.Length ) {
    61.              currentController = 0;
    62.          }
    63.          UpdateCameraControllers();
    64.          UpdateRayTransformControllers ();
    65.      }
    66. }