Search Unity

Problems in the direction

Discussion in 'AR/VR (XR) Discussion' started by BigB, Jun 11, 2015.

  1. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    Hi,

    There's a problem in that, when I move my head my scene view also moves, however when I move forward, the camera won't move in the new direction that I'm looking at, it will keep moving as if I didn't move my head at all.
    So basically, the only way to walk around my level is if I keep my head straigh, this way everything works, but the moment I start looking around, all the direction keys loose the orientation.
    What can I do so that Unity follows the direction that I'm looking at ?

    Thanks,
    Bruno
     
  2. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    One suggestion is, you can get the camera transforms' rotation, and use that to apply your motion.
     
  3. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    I think I didn't explained correctly the problem :)
    With the mouse, this works, I rotate the mouse around, and I'm able to move in the direction the mouse points at.
    The problem is with the rift.
     
  4. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Ah, sorry. This should help: http://docs.unity3d.com/ScriptReference/VR.InputTracking.html

    You could add a switch so that if you have VR enabled, it uses the rotation from InputTracking; otherwise, it uses the mouse movement: http://docs.unity3d.com/ScriptReference/VR.VRSettings.html

    Alternately, not syncing the movement to the VR device allows the player to look in a direction other that where they're moving - Although I don't know if that's useful for your project. Some games, including Team Fortress (IIRC) do that. In that case, adding a direction indicator (such as model legs and arms) to indicate heading and facing could also help.
     
  5. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    Thanks, I'l take a look at this, but how do we use this VR functions ?
    Whatever I use from here, I get compilation errors of not recognizing the functions, VR.Device, VR.Settings, etc.
     
  6. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Hmm...I just assumed they'd work. :( Let me add a check in a test project...it works.

    The code:
    Code (csharp):
    1.  
    2.   Debug.Log(VRDevice.family);
    3.   Debug.Log(VRDevice.isPresent);
    4.   Debug.Log(VRDevice.model);
    5.   Debug.Log(InputTracking.GetLocalPosition(VRNode.Head));
    6.   Debug.Log(InputTracking.GetLocalRotation(VRNode.Head));
    7.   Debug.Log(VRSettings.enabled);
    8.   Debug.Log(VRSettings.loadedDevice);
    9.   Debug.Log(VRSettings.renderScale);
    10.   Debug.Log(VRSettings.showDeviceView);
    11.  
    The results:
    Code (csharp):
    1.  
    2. oculus
    3. true
    4. Oculus Rift DK2
    5. (0.0, 0.0, 0.0)
    6. (0.0, 0.0, 0.0, 1.0)
    7. True
    8. Oculus
    9. 1
    10. True
    11.  
    Hmm...Do you have any legacy Oculus plugins hanging around?
     
  7. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    Nope, none of those commands are accepted by the compiler, it just fails "Unknown identifier "VRDevice".
    Do you have to install anything from Oculus ? I haven't installed anything from them, only the Oculus runtime.
    I'm with a DK1, but that should not make a difference I think.
     
  8. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Hmm...Try your own test project and run that code in a script? That would at least rule out a problem in your project.
     
  9. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    Same thing, new project, simple script with those debugs, doens't compile.
     
  10. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    I'm having a feeling it's too early to develop for the Rift.
    This entire part of Unity is full of bugs..
     
  11. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
    Try calling out the namespace explicitly (UnityEngine.VR.VRSettings, UnityEngine.VR.VRDevice). Or add usingVR = UnityEngine.VR; to your script.

    This is not the case here.. Is there something in your project that could be overriding movement? If you can reproduce in a simple scene please submit a bug report.
     
  12. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    @thep300 : Yes, that worked, now I can access the functions.

    I think the problem is that I'm using UFPS.
    How can I get the rotation of the Oculus ?
    I think it's probably with InputTracking.GetLocalRotation, but I'm unable to feed this function with something that doesn't give an error.

    UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.Head);

    How do I feed a parameter to this function ?

    Thanks,
    Bruno
     
  13. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
    Haven't used UFPS, but it will probably require some modification.

    UnityEngine.VR.InputTracking.GetLocalRotation (UnityEngine.VR.VRNode.Head); will give you the rotation of HMD, without being transformed by the camera's transform.
     
  14. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    Yes, that works :)
    Could you give me a hint on how to pass the direction of the Oculus to the camera ?