Search Unity

the camera of the oculus rift player prefab moves out of the rigidbody??

Discussion in 'VR' started by stefanwillems, Dec 7, 2016.

  1. stefanwillems

    stefanwillems

    Joined:
    Nov 2, 2016
    Posts:
    42
    i have the oculus rift player prefab in my scene. when i move around in real life in front of the sensor, the camera moves but the player holds the same position. so when i walk into a wall in game, i can move through the wall. how can i keep the camera in the player body?

    this is when i start up. and stand still:
    upload_2016-12-7_15-20-39.png
    this is when i walk (in real life in front of the sensor):
    upload_2016-12-7_15-21-17.png
    i want the green collider and the camera to move together. but how??? is this possible
     
  2. NickAtUnity

    NickAtUnity

    Unity Technologies

    Joined:
    Sep 13, 2016
    Posts:
    84
    VR cameras have a local offset applied by the VR system. This means that as you move around in room scale (or even around in front of a single sensor) your camera will be allowed to move outside of the character controller.

    Additionally, I'd recommend not bothering with a CharacterController at all if you're doing a room scale experience. CharacterController is intended for when you want to forcibly move a character in a scene, but with room scale you want the player's position in their play space to dictate their position (relative some point in the scene to account for moving through larger scenes).

    The best strategies I've heard of to deal with walking through walls tend to be things like applying some kind of effect to the camera so the user still perceives motion when clipping through walls but isn't able to see level geometry outside that they shouldn't. I don't have any examples off hand, but it's definitely one of those tricky problems with room scale VR.
     
  3. stefanwillems

    stefanwillems

    Joined:
    Nov 2, 2016
    Posts:
    42
    thanks for your reply. im using roomscale and a controller to move around. but i think it wil be a seated expirience from now on. the only head tracking used will be when your move your head left, right, up and down.
     
  4. jonnypage

    jonnypage

    Joined:
    Oct 21, 2014
    Posts:
    1
    Are you aware of any 'prefab' characterControllers that DO work with the oculus for locomotion around a room scale environment?
     
  5. ultimus11

    ultimus11

    Joined:
    Jul 13, 2017
    Posts:
    1
    You might have added Rigidbody component to the camera that is why its happening remove the Rigidbody component and it will work fine.
     
  6. Sasete

    Sasete

    Joined:
    Dec 17, 2018
    Posts:
    5
    I was having this problem recently and couldn't find any proper solution at all then generated my own solution. Here Im gonna detail it. Firstly my main problem was when player moved in real life then move over controller since its center collision is at different place it was stucking collision it shouldn't be such that when player tries to move just near table collider stucks at table but player's front looks like free to move.

    My Solution:
    Firstly I generated a script that carries collider to Center Eye Anchor's X and Z axises. Such that whenever player moves collider comes with it. It was okay for my problem but then I figured out this leads another big bug. It blocks us to bend over tables etc. it also blocks to goes inside walls which is okay but preventing us bending over objects is not good at all. So I generated another script which closes my first script at collider enter and placed this script over objects that I wanted to bend and when I exit trigger it is opening script back such that I can bend over everything that I want and also I don't stuck anywhere. It works well so far. If you get any bug over this let me know. Also here my scripts:

    Script for collision problem

    Code (CSharp):
    1. /*
    2. This code is generated by Sasete. reach me over here, SaseteS@icloud.com
    3. */
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using UnityEngine;
    7.  
    8. public class VRCameraCharacterControllerFix : MonoBehaviour {
    9.    
    10.     public CharacterController character;
    11.     public GameObject centerEyeAnchor;
    12.     private Vector3 place;
    13.    
    14.  
    15.     void FixedUpdate()
    16.     {
    17.         place = new Vector3(centerEyeAnchor.transform.localPosition.x, 0, centerEyeAnchor.transform.localPosition.z);
    18.  
    19.         character.center = place;
    20.     }
    21. }
    Script for closing first script

    Code (CSharp):
    1. /*
    2. This code is generated by Sasete. reach me over here, SaseteS@icloud.com
    3. */
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using UnityEngine;
    7.  
    8. public class VRCameraCollisionFix : MonoBehaviour {
    9.  
    10.     public GameObject OVRCameraRig;
    11.     private VRCameraCharacterControllerFix VRCameraCharacterControllerFix;
    12.  
    13.     private void Start()
    14.     {
    15.         VRCameraCharacterControllerFix = OVRCameraRig.GetComponent<VRCameraCharacterControllerFix>();
    16.     }
    17.  
    18.     private void OnTriggerEnter(Collider other)
    19.     {
    20.         if(TriggerVRObject(other))
    21.             VRCameraCharacterControllerFix.enabled = false;
    22.  
    23.     }
    24.  
    25.     private void OnTriggerExit(Collider other)
    26.     {
    27.         if (TriggerVRObject(other))
    28.             VRCameraCharacterControllerFix.enabled = true;
    29.  
    30.     }
    31.  
    32.     private bool TriggerVRObject(Collider other)
    33.     {
    34.         if (other.gameObject == OVRCameraRig)
    35.             return true;
    36.         else
    37.             return false;
    38.  
    39.     }
    40.  
    41. }
    42.  
     
    DemonDev10 likes this.
  7. Vinayak-VC

    Vinayak-VC

    Joined:
    Apr 16, 2019
    Posts:
    60

    Hey did this work?
    Cause when I tried this the collider was not moving perfectly with the camera.It was not like not moving at all.
    It was moving perfectly when I was looking forward but when I looked back the collider was far away from the camera so ,Player was unable to move.
     
  8. Vinayak-VC

    Vinayak-VC

    Joined:
    Apr 16, 2019
    Posts:
    60
    Hi There,
    I solved this problem by using buit in prefeb which is in the scene called "Locomotion" and its path is "Assets\Oculus\SampleFramework\Usage" and prefeb name is "PlayerController".

    It works like charm.
     
    MJonee likes this.
  9. Sasete

    Sasete

    Joined:
    Dec 17, 2018
    Posts:
    5

    This is how you use scripts, only first code is for OVRCameraRig it simply teleports OVR camera rig to the Center Eye Anchor's position continously.
    upload_2019-4-17_16-46-50.png


    And there is Wooden Platform that we have to bend over. To be able to do that, you have to enter this script over that, this script is just disable first script on trigger enter and when trigger exits re enable it

    upload_2019-4-17_16-49-42.png
     
    Vinayak-VC likes this.
  10. shafyy

    shafyy

    Joined:
    Aug 16, 2018
    Posts:
    1
    Yes, the `CharacterCameraConstraint.cs` script from the example scene Locomotion (Oculus Integration) solves the problem as @WR-reddevil suggested. I recommend adding that anyways, it also gives you the correct height for the player.
     
    MJonee and JasperCiti like this.
  11. MJonee

    MJonee

    Joined:
    Oct 19, 2013
    Posts:
    20
    Yes, just add CharacterCameraConstraint.cs and it will work
     
  12. Roetty

    Roetty

    Joined:
    Oct 8, 2019
    Posts:
    1
    Hi, correct :). Make a Capsule, put the OVRCameraRig into as a Child and add the CharacterCameraConstraint Script to the Capsule. That´s it. GREAT :)
     
  13. raeldor

    raeldor

    Joined:
    Jul 8, 2013
    Posts:
    55
    I tried this as of September 2020, and it no longer seems to work. In fact, building the original sample doesn't work either... no collision checking when moving in room scale seems to take place at all.
     
    VirtualDawn likes this.
  14. UnityQueries

    UnityQueries

    Joined:
    Jul 6, 2021
    Posts:
    9
    Hi All, I am also getting the same problem. I have added the CharacterCameraConstraint script to my PlayerController but still I am getting same problem.

    Can anyone please help me to resolve this problem?

    Thanks in advance.
     
  15. eovento

    eovento

    Joined:
    Feb 22, 2018
    Posts:
    38
    Dude, I can't thank you enough. I've been struggling with it for 2 years in my project. THANKS!!! I feel like celebrating now! haha I would hug you if I was close!