Search Unity

  1. Unity wants to learn about your experiences working on a Unity project today. We'd like to hear from you via this survey.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Proper way to rotate VR camera.

Discussion in 'AR/VR (XR) Discussion' started by seanybaby2, Apr 11, 2018.

  1. seanybaby2

    seanybaby2

    Joined:
    May 17, 2013
    Posts:
    120
    I'm having difficulty figuring out the proper way to rotate a VR camera.

    Currently the position and the rotation of the headset is unreadable and sets based off of your hardwares tracking. The current well known work around for creating movement or rotation for the player is is to create a parent object and move or rotate that parent object instead of the camera. The problem with this is when rotating the parent the rotation is based off of the pivot of the parent object and not of the camera. This can create some terribly offset rotations for people using room scale tracking. What is the work around for this? I'm sure I'm not the only one who has ran into this problem.
     
    Piedpiperz80 likes this.
  2. darkesco

    darkesco

    Joined:
    Mar 19, 2015
    Posts:
    51
    There is no workaround. It's broken
     
  3. farzaan090

    farzaan090

    Joined:
    Jul 23, 2018
    Posts:
    15
    Did you happen to find any solution here? I've reached this problem now and cannot think of a solution.
     
  4. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    606
    rotate the parent with an offset set to your cameras position.
     
    joelybahh likes this.
  5. joelybahh

    joelybahh

    Joined:
    Mar 18, 2015
    Posts:
    66
    You can rotate the parent around the head's position, that way you don't rotate around the playspace center, but instead around the head center :)
     
    Piedpiperz80 and hawken like this.
  6. joelybahh

    joelybahh

    Joined:
    Mar 18, 2015
    Posts:
    66
    Code (CSharp):
    1. parentTransform.RotateAround(new Vector3(HeadTransform.position.x, 0, HeadTransform.position.z), Vector3.up, 45.0f);
     
  7. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    629
    For my game I have it as it's been explained before:

    Empty Parent GameObject
    - Main Camera
    - UI Camera

    If I want to force the player to look in a particular direction, I simply edit the transform of the Empty Parent GameObject.

    When I fade out, I use a fade sphere around the Empty Parent GameObject so that all of the cameras get enshrouded in darkness. When it's faded out, I can then subtract the Main Camera rotation from the Empty Parent GameObject rotation.....or....something I'd have to look at how I did that, but it certainly is possible to get the player to be forced to look in a particular direction.
     
  8. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    606
    I just checked since it's been a while since implementing this and I'm using Steam Fade + rotate around.
     
  9. farzaan090

    farzaan090

    Joined:
    Jul 23, 2018
    Posts:
    15
    Awesome, I didn't realize that was possible!

    I ended up raycasting where the camera was, rotating the parent of the camera, raycasting the new position of the camera, then moving the parent object the same as the difference between the raycast...

    Needless to say, this is significantly simpler. Thanks!
     
    joelybahh likes this.
  10. joelybahh

    joelybahh

    Joined:
    Mar 18, 2015
    Posts:
    66
    Not a worry at all :)
     
    Piedpiperz80 likes this.
  11. darkesco

    darkesco

    Joined:
    Mar 19, 2015
    Posts:
    51
    There is a movement option for this in the oculus sample framework. It's also being used in Dash home too. The character controller can now follow the head when you walk, that way both objects rotate correctly. In oculus home, look down. That circle on the ground is your invisible character controller's feet. Walk a few feet and watch it transition to your new location.
     
  12. joelybahh

    joelybahh

    Joined:
    Mar 18, 2015
    Posts:
    66
    This is easy to mimic in unity by using the default character controller, and overriding the 'center' to equal your heads local X and Z position.
     
    dubkacik1 likes this.
  13. joelybahh

    joelybahh

    Joined:
    Mar 18, 2015
    Posts:
    66
    You can take this further and set the height of the character controller to the distance between your head and the playspace, that way you have a character controller that follows your real position, and adjusts to your height in realtime :)
     
  14. darkesco

    darkesco

    Joined:
    Mar 19, 2015
    Posts:
    51
    How do you override the center? Doesn't altering the center, just push your head out further? Could you explain how to do this? I don't want to use all the extra stuff in the framework and would rather just adjust the standard ovrplayercontroller.
     
  15. joelybahh

    joelybahh

    Joined:
    Mar 18, 2015
    Posts:
    66
    So I'm talking about unitys built-in CharacterController component, you simply need to set the center variable on the component to equal the local X and Z of the head. That way the controller will always be in line with your head, imitating the behavior seen in Oculus Home.
     
  16. darkesco

    darkesco

    Joined:
    Mar 19, 2015
    Posts:
    51
    Thank you. I'll give this a try. I like the input scripts on the OVR stuff and have exploited screen fades and things so I'll need to walk back a lot of that or learn how to use the OVRPlayerController script on the unity char controller. Wish Oculus had just added the ability to walk and rotate from the start. Very confusing to beginners.
     
  17. seanybaby2

    seanybaby2

    Joined:
    May 17, 2013
    Posts:
    120
    This is the solution. It's hacky as hell but it's the standard AFAIK. You have to create an artificial offset for the roomscale. Just subtract the difference between the camera position and the tracker center point. I got some code I can copy pasta if anyone needs it.

    You have to do this every frame by the way.....
     
  18. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    606
    use RotateAround(), it's much less painful.
     
unityunity