Search Unity

OVRPlayerController Proper Usage

Discussion in 'VR' started by nols, May 31, 2019.

  1. nols

    nols

    Joined:
    Aug 24, 2018
    Posts:
    3
    I am tinkering with with the Oculus Quest and I'm learning how to use the OVRPlayerController. After getting the settings all correct, I added the DistanceGrabHandLeft and DistanceGrabHandRight prefabs. I got those rigged up and working. I have joystick movement enabled and have found that the forward direction doesn't adjust based on anything.

    There is a "ForwardDirection" game object that is a child of the OVRPlayerController game object. I lazily assumed that this defined forward without looking at the code so I added a script that would allow me to adjust the transform of that based on the LeftControllerAnchor game object's transform (or head or right controller) in the Update(). Then I realized this wasn't working so I looked at the code of OVRPlayerController and found in UpdateMovement():

    Code (CSharp):
    1. Quaternion ort = transform.rotation;
    2. Vector3 ortEuler = ort.eulerAngles;
    3. ortEuler.z = ortEuler.x = 0f;
    4. ort = Quaternion.Euler(ortEuler);
    5.  
    6. if (moveForward)
    7.     MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * Vector3.forward);
    8. if (moveBack)
    9.     MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back);
    10. if (moveLeft)
    11.     MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.left);
    12. if (moveRight)
    13.     MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.right);
    So I changed the transform for this part from OVRPlayerController to be the transform of ForwardDirection.

    This seems to be working fine but feels wrong. Is there a more correct way to do this? I am using version 1.37 of the Oculus Integration.
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Welcome to the forums!

    So, I've only been working with the Oculus Integration (and, similarly, VR development) for a few months now. First with the Go, and now with the Quest. I'm not too deep into things and getting all the features setup, but my conclusion at this point is that

    The Oculus SDK is a freakin' mess.

    The OVRPlayerController, in particular, has a lot not to like about it. It seems to have been designed, originally, for use with linear movement (using an Xbox controller, for example) and has had a bunch of things tacked onto it since. Many of the components included in the integration aren't documented, or are even documented incorrectly.

    The documentation says of ForwardDirection:
    Hmm. Okay. I'm not sure why the player's geometry would be a child of ForwardDirection, but... Let's look at TrackingSpace to see if that clears it up.

    It doesn't mention ForwardDirection at all! So where do I find out what ForwardDirection actually does?!

    - - -

    I'm trying to suss it all out. A lot of folks around here will tell you to ignore Oculus's integration stuff, but it feels like it should be used. And there's a lot of good functionality there, if you can figure out how to get to the creamy goodness inside.

    If I do figure it out, I plan on doing a writeup and sharing some samples to help others along. Keep digging, though, and see what you can come up with!

    Good luck!
     
  3. nols

    nols

    Joined:
    Aug 24, 2018
    Posts:
    3
    Thanks for the feedback. I forgot about the snippet that the body geometry should be housed by ForwardDirection so I guess I shouldn't use it the way I am. But for right now, here's what I've added to it to make it work:
    On the ForwardDirection game object:
    Code (CSharp):
    1. public class OVRForwardDirectionBinding : MonoBehaviour
    2. {
    3.     public enum MovementController
    4.     {
    5.         Tracker,
    6.         LeftController,
    7.         RightController
    8.     }
    9.  
    10.     public Transform TrackerAnchor;
    11.     public Transform LeftControllerAnchor;
    12.     public Transform RightControllerAnchor;
    13.     public MovementController MovementBasis;
    14.  
    15.     private Transform forwardTransform;
    16.  
    17.     private void Start()
    18.     {
    19.         switch (MovementBasis)
    20.         {
    21.             case MovementController.Tracker:
    22.                 forwardTransform = TrackerAnchor;
    23.                 break;
    24.             case MovementController.LeftController:
    25.                 forwardTransform = LeftControllerAnchor;
    26.                 break;
    27.             case MovementController.RightController:
    28.                 forwardTransform = RightControllerAnchor;
    29.                 break;
    30.             default:
    31.                 forwardTransform = LeftControllerAnchor;
    32.                 break;
    33.         }
    34.     }
    35.  
    36.     // Update is called once per frame
    37.     void Update()
    38.     {  
    39.         transform.rotation = forwardTransform.rotation;
    40.         transform.position = forwardTransform.position;
    41.     }
    42. }
    And then on the OVRPlayerController, I added:
    Code (CSharp):
    1.     /// <summary>
    2.     /// Transform that defines how joystick movement should affect player.
    3.     /// </summary>
    4.     public Transform ForwardTransform;
    I modified the snippet from UpdateMovement() to use the ForwardTransform instead of transform (which is the Transform of the OVRPlayerController game object). I used the empty ForwardDirection game object for ForwardTransform.

    It sounds like I'm not misusing this too much. I think I'll just move the OVRForwardDirectionBinding onto the OVRPlayerController script and have it set ForwardTransform to one of the three game objects (tracker, left, or right controller). I was just hoping there would be a way to do this without having to modify a script that will be replaced with updates to the integration.