Search Unity

Cinemachine in VR

Discussion in 'Cinemachine' started by Vallar, Nov 1, 2019.

  1. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Hey all,

    I was wondering if someone tried to use Cinemachine in VR as the main camera (the one controlled by the HMD)?

    I tried the other day and put the TrackPoseDriver on the Cinemachine camera but for some reason the Camera always appears with an offset in Z so far that to see my hands I have to look behind me. I am using a virtual camera with Do Nothing on both the Body and Aim.

    Any ideas what the issue could be? Main camera (without Cinemachine) works better overall.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    There is no reason why you wouldn't be able to replace the Camera component in your working setup with a CinemachineVirtualCamera with DoNothing in Aim/Body. Then, make a Camera GameObject separately and add a CM brain to it.

    What did you do that was different?
     
    FNaFfan1234 likes this.
  3. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Nothing. Fresh scene, created Cinemachine Virtual Camera. Next I added TrackPoseDriver on the Main Camera (the one created with the scene). I found a weird offset. So I thought maybe TrackPoseDriver shouldn't be on Main Camera and I placed it on Cinemachine Virtual Camera instead. Still same offset.
    So I caved and removed Cinemachine and disabled Cinemachine Brain on Main Camera. Next I applied TrackPoseDriver and it actually worked. There is still an offset in the Z but it is far less than Cinemachine. Like Main Camera is set at 0, 1.3, 0 at the moment. When I play that changes to whatever in X, 1.3 in Y but Z remains at 0.6. When I was using Cinemachine that Z offset was far greater than 0.6 (was like 1.8 or 2) so hands were always behind me. Don't know why this happens.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I think you need to understand what this offset is, to gain control of your scene.
    I'm not familiar with TrackPoseDriver, so can't help you with that one.

    Is it possible that the offset comes from some initial position of the object you add it to? Try placing both the Camera and the vcam at the origin before adding it.
     
  5. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    This is why I posted here, hoping to find out where the offset comes from.

    I did put both at origin and still the same issue persists. I then thought perhaps because the Cinemachine camera need to be parented for this whole issue with how HMDs check for origin (some do it as the real origin and some do it as the HMD or at least that is my understanding). So I placed the camera along with the controllers under an "Offset" empty game object. Same results still. Placed them all at Unity's origin, same issue. Added a custom offset, nothing different.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Can you show an image of your hierarchy, so I can see how you've set it up?
     
  7. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Well it all looks fine at the hierarchy level. I really don't see where CM would be introducing an offset, if you're using DoNothing in the body. Can you show some relevant inspectors?
     
  9. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    I was about to so when I thought perhaps I should just create a new scene from scratch and work through it (for the second or third time) and I did that and surprisingly it worked this time.
    Going to test a bit more and report back if there is any issue.

    Thanks again, Gregoryl! :)
     
  10. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    360
    i recently have a project that needs to support cinemachine and VR. it's a troublesome. for cinemachine, you are controlling the camera. for VR, you are supposed to control the standing point and allow player to move their head in 6DoF, and the scale matters.
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I'm not sure what "needs to support cinemachine and VR" means exactly. Can you be more specific about the needs of this project?

    In general, CM can be used with an XR headset. See this post: https://forum.unity.com/threads/res...-with-xr-virtual-reality.817074/#post-5454426
     
  12. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    When I try to use Cinemachine in VR I get the following warnings repeatedly:

    Cannot set field of view on camera with name 'MainCamera' while VR is enabled.
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    Cinemachine.CinemachineBrain:pushStateToUnityCamera (Cinemachine.CameraState&) (at Library/PackageCache/com.unity.cinemachine@2.7.9/Runtime/Behaviours/CinemachineBrain.cs:866)
    Cinemachine.CinemachineBrain:processActiveCamera (single) (at Library/PackageCache/com.unity.cinemachine@2.7.9/Runtime/Behaviours/CinemachineBrain.cs:639)
    Cinemachine.CinemachineBrain:ManualUpdate () (at Library/PackageCache/com.unity.cinemachine@2.7.9/Runtime/Behaviours/CinemachineBrain.cs:381)
    Cinemachine.CinemachineBrain:LateUpdate () (at Library/PackageCache/com.unity.cinemachine@2.7.9/Runtime/Behaviours/CinemachineBrain.cs:336)
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
  14. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
  15. ristophonics

    ristophonics

    Joined:
    May 23, 2014
    Posts:
    32
    I followed the steps, more or less, and got good results. I'm using the standard XR rig but with Cinemachine on top.
    If the game detects a XR headset, on start, it shutdowns the cinemachine cameras and brain so the XR rig can control the Main camera. If there is no headset cinemachine takes over and activates two virtual cameras. The first virtual camera basically sits on the XR rig doing nothing, mimicking a regular camera. The second virtual camera follows the car with cinemachine coolstuff. When the driver toggles cameras, virtual camera one will turn off and on. This creates a seamless transition from first person driving view to cinematic follow view and back. The first and second virtual cameras manage the transition with their priority value, when only the first camera is toggled on or off. It was a big thing to add to my old game, using 2019LTS, but I am very happy with the results out of the box. Thanks for all the work and threads that help me get here. If the thread ain't dead I can post more info on my setup with the XR rig and Cinemachine. Best Moga

    boost.gif