Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Custom 1st person port with oculus

Discussion in 'Cinemachine' started by nathanjams, Nov 6, 2017.

  1. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Hello,

    Been using Cinemachine for almost a week now and am wishing I had started a long time ago!

    I have a vague question about how the camera anchors to Vitrual Cameras on start and an issue I've not really been able to figure out. I'm using Ootii's Motion Controller to control a 3rd person character and I've been trying to get a pseudo 1st person build out of it.

    If I follow the settings from the Unite Presentation with the Mouse demo I can get the POV camera to achor properly to the Player's head and run the scene without the VR headset. However, if I plug the Oculus Rift in and try the scene in VR the Camera fails to attach to the POV Virtual Camera.I can get the Main Camera to achnor properly to the POV VC if I place the camera inthe Player's head Game Object (in the same object as the POV VC).

    I'm not sure why this is but it seems to work - with that said, I am having issues triggering othera cameras and am wondering if this is related. I know that this is not ideal and was wondering if anyone here had any ideas of why this would be or have a solution for removing the Main Camera from the Player.


    Thanks in advance. Really excited about the possibilities of developing with this asset.

    Nathan
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    So the thing with VR is that it wants to control the camera. Cinemachine also wants to control the camera, so you have to do a little persuasion to get them to work together.

    The way to move the VR headset around in your world is to put it into a container object and move that. If you can get Cinemachine to move that container object around instead of the camera, then it should work. Cinemachine 2.1 has removed the restriction that the CinemachineBrain must be on a Unity Camera, so this is possible with that version of CM.

    By default, when you use CM to create a virtual camera, it will create a CinemachineBrain on the main camera, if there is not already a CinemachineBrain in the scene. So, all you have to do is to create a CinemachineBrain on your camera container object beforehand. You can remove any CM brain that was already created on the Camera if you have any. You may also need to create a disabled Unity Camera alongside the CinemachineBrain (this is only if you're using the layering system with the vcams - the Brain will want to look at the Camera's layer mask).

    That should do it. CM will then drive the camera container instead of the camera itself, so will play nicely with VR. Obviously, the Lens Settings features of CM will have no effect.

    Let us know how it goes.
     
    Last edited: Nov 6, 2017
    nathanjams likes this.
  3. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Thanks for the thorough response, @Gregoryl

    I'm happy to report that we have it working much better than I was expecting at this point! However, there is one issue I can't figure out.

    We're using the POV option (for the Aim field of the Virtual Camera) as this allows us to rotate the player's axis (by selecting "Rotate with Camera" in Ootii's Motion Controller). As this is based off an Axis input its values range from 180 to -180. The problem I can't figure out is that if the player rotates to 180 degrees the value can't go beyond. Further, if they release the input button and then try to turn again the value is still at 180.

    So, two questions.

    1. Is it possible to not lock these values as such?
    and/or
    2.Is there a way to reset the value when the player lets go of the axis input?

    Thanks again,

    Nathan
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Yes. There is an error on line 42 of CinemachinePOV.cs. Just change the line to
    Code (CSharp):
    1.             m_HorizontalAxis.SetThresholds(-180f, 180f, true);
    We will include this change in the next RC.
    Not sure what you mean by "reset the value". Do you mean set the X and Y axis values to 0, thus re-orienting the camera?
     
    nathanjams likes this.
  5. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    That was 100%, completely it. Thank you!!!