Search Unity

VROne / Camera Rotation

Discussion in 'AR/VR (XR) Discussion' started by infinitypbr, Dec 17, 2014.

  1. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    I'd like to modify the rotation of the camera object via a gamepad. I have code that works in the editor, but doesn't work on iOS. (However, it looks like it's working but being pushed back on the 2nd frame by the VROne code).

    I was able to get this working w/ the Rift, but haven't been able to figure it out with VROne yet. For the Rift I added an "offset" to the rotation that was changed by the GamePad joystick. The offset was calculated into the final rotation that also includes the players look direction.

    Any idea what part of the code I'd modify to get this properly working with the VROne sdk?
     
  2. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Probably best to ask on the VROne forum.

    But from the sounds of it if you attach a gameObject to the camera as it's parent then you should be able to rotate this object using the gamepad and have the transform of the child or camera.
     
  3. Pete-Moss

    Pete-Moss

    Joined:
    Mar 18, 2013
    Posts:
    15
    I havent used the VROne yet, so I am not sure what to say. I agree with Arowx that it might be a chance to use the hierarchy to solve the problem, where the parent is controlled via gamepad, and the child is controlled by head rotations of the user.
     
  4. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    I'll try adding a new parent level when I get home.

    I feel like I tried that with the rift months ago, and it didn't work, but I can't quite remember.

    The vrone currently uses stack exchange as its forum, with vrone and unity3d tags, but there's only two posts and zero replies so I'm not sure if they're active with it yet.
     
  5. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    EDIT: The below code works in editor but not on the iOS device. See next reply for more info.

    Alirght -- thanks for the tip!

    I've made the camera object a child of an empty object. One problem is that the rotation on the parent would affect the child too, so the child needs to be at localPosition 0,0,0, and then I use the following code during the rotation to make sure that as the child moves (which is what moves with the character controller), the parent stays in the same spot and the rotation looks normal.

    Code (csharp):
    1.  
    2. if (RightStickX.Value != 0)
    3. {
    4. transform.position = childObject.transform.position;
    5. childObject.transform.localPosition = Vector3(0,0,0);
    6. transform.eulerAngles.y += RightStickX.Value * rotationSpeed * Time.deltaTime;
    7. }
    8.  
    I haven't tried moving the character controller to the parent, however, so that may work, I'm not sure if that would mess with anything in the VROne SDK.
     
    Last edited: Dec 18, 2014
  6. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    On the VROne forum they suggested the offset value received by the gamepad be added to line 43 in the HeadTrackingIOS class.

    That line is as follows:

    Code (csharp):
    1. return new Quaternion(q[0], q[1], q[2], q[3]);
    I'd like to add my offset to that, however I'm not the best at C# code and what I've thought may work doesn't seem to be working. Any chance I can get an assist?

    My code that doesn't work:

    Code (csharp):
    1. Quaternion angleReturn = (Quaternion(q[0], q[1], q[2], q[3]) + Quaternion.Euler(0, offsetY, 0));
    2. return angleReturn;
     
    Last edited: Dec 18, 2014
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The code is nonsense due to poor copy and paste formatting, so here are the fixed versions in case this was the problem:

    ---

    return new Quaternion(q[0], q[1], q[2], q[3]);

    Quaternion angleReturn = (Quaternion(q[0], q[1], q[2], q[3]) + Quaternion.Euler(0, offsetY, 0));
    return angleReturn;

    ---

    In addition, some notes: You can't add quaternions. You should multiply them together.
     
  8. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    Ah yes, these forums do tend to remove those spaces. Fixed.

    The error I'm getting, which doesn't make sense to me, is: Expression denotes a `type', where a `variable', `value' or `method group' was expected