Search Unity

cameras in VR mode with unity 5 rift 0.7

Discussion in 'AR/VR (XR) Discussion' started by steveh2112, Sep 19, 2015.

  1. steveh2112

    steveh2112

    Joined:
    Aug 30, 2015
    Posts:
    314
    so i have a flight sim app that has 3 predefined cameras (cockpit, tail and wing) and i can switch between them with keyboard or joystick and all works fine on PC.

    when i go to VR mode, it comes up fine in my DK2 and seems to work well, i can look around, move my head up and down (even poke my head outside the cockpit!). but the camera switching doesn't work.

    i understand that it shouldn't i guess, based on this doc:
    http://docs.unity3d.com/Manual/VROverview.html

    but i would like to be able to at least move the VR POV with a key or joystick button, so i can so i can stand on the tail or wing as well as in the default position in the cockpit.

    how would i go about that? moving the camera position and rotation relative to the player? i don't really understand the camera in VR mode at all.

    (BTW, i've noticed a lot of info on this subject is outdated based on old versions of unity and rift SDK so i really what to get the current, best way to do it).

    thx
     
    Last edited: Sep 19, 2015
  2. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    I'm doing something similar and am not having any problems switching cameras. Here's what I do, effectively:

    Say I have two cameras. Each has a parent game object that I use for moving the cameras around. Sounds like you probably have this part working already:

    ParentEmptyGameObject1->CameraGameObj1
    ParentEmptyGameObject2->CameraGameObj2

    When I want to switch cameras I just turn ParentEmptyGameObject1/ParentEmptyGameObject2 on and off (SetActive()) which also turns off the children. Are you doing that or are you just disabling the camera scripts on the cameras, by chance?
     
  3. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    Oh, wait, I just realized you were talking about 0.7. Sorry, I haven't tried that. I'm on 0.6 still.
     
  4. steveh2112

    steveh2112

    Joined:
    Aug 30, 2015
    Posts:
    314
    Thanks, Todd, i'm doing the same thing and it works fine on the monitor but not in VR mode (rift), i think because rift overrides the cameras and replaced it with a special VR stereo camera, but i'm not sure. are you OK on rift with camera switching?
     
  5. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    I found it's easiest for me to just have multiple camera game objects (each with a parent so head tracking works) and make sure only one parent is turned on at a time. So if you have one in the cockpit and one on the tail, make sure only one is active at a time. When you switch to tail view or whatever, just turn off all the parent game objects and then turn on the one you want.

    I tried doing it at one point by having only one camera in the scene, but in my case that doesn't really work because different cameras work differently in my system. I have one that's an onboard view that you can pan around with the mouse, another that's an external orbit cam that swings around my boat with the mouse, and another type that drops into the water and follows the boat as it drives by:




    These views all work just fine in VR, I don't have to change anything for non-VR. I put all my camera control scripts on the parents and just move those. So in the parts where the boat is flying by, in VR it's like your body faces the camera to follow the boat, but you can still turn your head and look around.

    Once you put a parent object on the camera, it's not really operating very differently in VR mode than non-VR mode. The only thing different is that the main camera game object (the child) is being controlled by the Rift. So instead, just do all your camera movement stuff on the parent, and turn the parents on/off to switch cameras. Always make sure you only have one camera turned on at a time though. Otherwise you can get a massive frame rate hit, or at least you used to.
     
  6. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    Yes, camera switching works fine in VR, at least on 0.6. Haven't tried 0.7 yet.
     
  7. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    It's confusing to try to think about the extra cameras that are being created. Don't worry about that, just think of it like a single camera. The double camera stuff is all behind the scenes. Thinking about those will just confuse us. :p
     
  8. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,137
    What I'm doing is to not actually have multiple cameras but camera placeholders.When switching, I simply parent the camera to the new position placeholder. One must make sure though that the placeholder orientation is set up as needed.