Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

(Unity) OVRPlayerController- How to get OVRPlayerController to move with OVRCameraRig

tkdHayktkdHayk Posts: 32 Oculus Start Member
I'm working off the standard OVRPlayerController, which has an OVRCameraRig as its child.
This is a game where I need thumbstick locomotion (which the OVRPlayerControllerProvides), but I also need roomscale movement. In other words, I need to make sure that when the player moves physically, his in game avatar should also move.

Currently whats happening is that when the player moves physically, the OVRcameraRig moves with him, but the parent OVRPlayerContoller does not move. This is an issue because I need my OVRPlayerController to move with my player at all times for proper collision tracking and targeting by Hostile AI. 

What is the best way to achieve this? Iv'e tried a few ways to make it work but wondering what the cleanest solution is. I'll also need hand tracking for this game. Perhaps I should simply use the AvatarSDK standard avatar and make it a child of a Character Controller for thumb stick movement? 

thanks for the help!


Comments

  • tkdHayktkdHayk Posts: 32 Oculus Start Member
    edited October 2017
    hi imperativity,

    Yes I have skimmed over the AvatarSDK guide and there is no info regarding how to get AvatarSDK working with OVRPlayerController in such a way that the  OVRPlayerController moves with the OVRCameraRig, preventing the player from walking away from his body (OVRPlayerController). The Avatar hands are working fine, I have no problem with them. Thanks,

    hayk
  • tkdHayktkdHayk Posts: 32 Oculus Start Member
    @tkdHayk

    I have elevated this and your other forum request to the Avatars team for their consideration on making a tutorial within the documentation to achieve this behavior. Hopefully this will be up by the end of the year.

    Thank you,

    that's a good idea! Please alert me when this happens as I might miss it in the documentation.

    The closest solution I have found is:

    OVRPlayerController
        (child) OVRCameraRig
                      (child) Tracking Space
                               (child)LocalAvatar

    I still cannot figure out how to make the character controller follow the avatar so that collision detection with the environment is accurate while moving  with artificial locomotion. It is possible to put the character controller and the terrain on their own layer which ignores all other layers to disable the character controller colliding with the environment, and then to use use custom colliders on the head/body of "local avatar" for game collisions. However, there must be a cleaner solution wherein the character controller actually follows the local avatar. 

    Hayk
    [email protected]




  • Mr_GoodKatMr_GoodKat Posts: 34
    Brain Burst
    Was this resolved? If so, what was your solution? 

  • DabszuDabszu Posts: 2 Oculus Start Member
    Hi there, I'm also having this issue and would welcome any potential solution.

    Thanks!
  • KatagenaKatagena Posts: 1
    NerveGear
    Same problem here if anyone have a solution...

    Thanks ! 
  • DigitalDownbeatDigitalDownbeat Posts: 3 Oculus Start Member
    edited June 2018
    I found a solution. You have to update the Vector3 property called 'center' in the CharacterController component of your OVRPlayerController. I am now able to walk in the real world and fall off of a cube :smile:

    Let me know if it works or you guys have any other ways to do it.

    YourScript.cs:
    //add these inside your class
    //Make sure you bind this in Unity by dragging the OVRPlayerController from the Hierarchy to the script
  • tkdHayktkdHayk Posts: 32 Oculus Start Member
    @DigitalDownbeat

    Thanks for that! It is not a complete solution but it provided a very interesting hoverboard effect. Because the Camera is a child or grandchild of the player controller, as the Playercontroller moves towards the camera, the camera moves away (because it is a child of the Playercontroller) The PlayerController never catches up to the camera and keeps moving across the scene. 
  • baroquedubbaroquedub Posts: 9
    NerveGear
    edited December 2019
    As far as I can tell, the intended work around is to add the CharacterCameraConstraint script to your OVRPlayerController.

    This provides you with the option to 'Enable Collision' but as the tooltip says "When true, the camera will be prevented from passing through collidable geometry. This is usually considered uncomfortable for users." Try it and you'll see that you get pushed back if you try to physically walkthrough geometry. It's a pretty odd sensation but it does keep CharacterController and the OVRCameraRig in sync.

    A possibly better option is to use 'Enable Fadeout', which instead fades the camera view to black when you start to physically walk through geometry. This tends to have the effect of stopping the player in their tracks, which minimises the likelihood of CharacterController and the OVRCameraRig getting offset, but of course doesn't guarantee it.

    If you go for the Fadeout option, it's worth knowing that in Oculus Utilities v1.43.0, OVRPlugin v1.43.0, SDK v1.44.0 the lines of code that are activated by `if(EnableFadeout){`... are actually commented out and so this option no longer does anything. it appears to be because the OVRInspector.instance.fader instance no longer exists in the newer codebase.
    To get around that, you can add a copy of OVRScreenFade on the OVRPlayerController gameObject and reference that instead.

    So in CharacterCameraConstraint.cs:
    //if (EnableFadeout)
    //{
    	//float fadeLevel = Mathf.Clamp01((CurrentDistance - FadeMinDistance)/ (FadeMaxDistance - FadeMinDistance));
    	//OVRInspector.instance.fader.SetFadeLevel(fadeLevel * MaxFade);
    //}
    	
    becomes
    if (EnableFadeout)
    {
    	float fadeLevel = Mathf.Clamp01((CurrentDistance - FadeMinDistance)/ (FadeMaxDistance - FadeMinDistance));
    	OVRScreenFade _screenFadeScript = GetComponent<OVRScreenFade>()
    if(_screenFadeScript != null) _screenFadeScript.SetFadeLevel(fadeLevel * MaxFade); }
    Of course you're better off caching the reference to the OVRScreenFade component (or even adding one dynamically in Start() `if(EnableFadeout)`

    Also it's worth bearing in mind that the mesh quad that OVRScreenFade creates to blackout the player's view isn't ideal for this application - you can see its extents if you gaze up or down. I've ended up creating a cube mesh (with inverted normals) so that the entire view goes black.
Sign In or Register to comment.