Search Unity

Question about Parenting to VR Headset, This must be easy...

Discussion in 'AR/VR (XR) Discussion' started by beowulfkaine, Jun 28, 2016.

  1. beowulfkaine

    beowulfkaine

    Joined:
    Apr 3, 2014
    Posts:
    185
    Hey all, I'm basically creating a gun holster for the game character VR and (HTC VIVE) and basically the problem I'm having is that the holster wants to keep moving when I parent it tot the camera object, obviously that is whats suppose to happen but I basically want it to remain stationary like a belt where the player can look down and see it but still follow the player as if its on his body. What am I doing wrong, whats the best way to achieve this?
     
  2. EdBlais

    EdBlais

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    311
    It shouldn't be a child of the Camera. It should be a child of the Camera's parent. That way it won't get the rotation of the Camera.
     
  3. beowulfkaine

    beowulfkaine

    Joined:
    Apr 3, 2014
    Posts:
    185
    Well the Camera rig is the entire play area, then you have the camera head, then the two controllers. If you make it a parent of the [camera rig] it basically just stays in place in within the entire work area and you can walk around them, they dont actually follow the player (Camera Head)
     
  4. BDFgames

    BDFgames

    Joined:
    Apr 17, 2015
    Posts:
    26
    Contending with similar issues. Did you ever find a good solution?
     
  5. NickAtUnity

    NickAtUnity

    Unity Technologies

    Joined:
    Sep 13, 2016
    Posts:
    84
    One suggestion would be to keep it as a separate root game object and update it's position based on the camera's position. You could, for example, store a Vector3 offset from the camera when the player holsters the gun and then make sure the gun is kept at that offset each frame.

    You can also use the InputTracking.GetLocalPosition method to get the position of the head without having to access the camera transform, if you want the holster object to be more self contained and not reference the other game object.
     
    Last edited: Nov 4, 2016
  6. tango209

    tango209

    Joined:
    Feb 23, 2011
    Posts:
    379
    One technique I use is to freeze the rotation of my player's load bearing equipment when the headset looks down past a certain angle allowing them to access anything they have attached to it. Only drawback that I see so far is when there head is turned quite a bit from center.
     
  7. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Make a follow script, that follows the camera on the x/z axis, and positions itself halfway up on the Y. For rotation, you want to follow the head on the Y axis, but ignore X and Z.

    You can keep the holster as a child of your camera in the editor, but then have it unparent itself at runtime, so it doesn't inheret the parents position.