2

Currently I am working on a game for people with accessibility restrictions. I am having the issue of locking the player model in a sitting position. If the user does not center themselves in the room the player model will be pulled to a certain direction. I would like to lock the player model in a seat and only allow for arm movements and head rotations, no leaning or moving in the game using the HMD.

Since I am using the Final VR IK asset I have tried using their demo for sitting position in VR and cannot get the player to stay seated naturally. I am not sure how to program this or set restrictions to be able to do this.

Edit: To simplify my question. How do you lock the oculus rift HMD to only allow for rotation and not position tracking.

Afroca
  • 115
  • 11
  • 1
    I don't know anything about Final IK's api but I would look for a way to set something like a target position and rotation for the character's chest. Good luck! – Ruzihm Jul 19 '19 at 15:49
  • 1
    @Ruzihm Thank you! I will look into that. – Afroca Jul 19 '19 at 17:31
  • @Ruzihm Could you take a look at [this question](https://stackoverflow.com/questions/57275200/unity-oculus-locking-hand-positions-in-1-axis-while-allowing-for-movement-in-the) – Afroca Jul 30 '19 at 15:30

1 Answers1

2

I figured it out how to lock the HMD into to only allow for rotation and not position tracking. To add a sitting position just use an body animation that's sitting. There are 2 things I did. First I added a line of code to the OVRCameraRig script:

trackingSpace.localPosition = -1 * centerEyeAnchor.localPosition;

This was done right before the RaiseUpdatedAnchorsEvent(); call around line 260 in the UpdateAnchors() method. What this does is it locks the head position and only allows for head rotation.

The second thing I did was write a head relocation script based on @derHugo answer to one of my other questions. What this does is when the space bar is pressed it will move the entire OVRCameraRig position. There must be a parent on OVRCameraRig for this to work In the screen shot below you can see the CameraParent object as the parent. I used a sphere as the relocation object that was placed in the middle of the head of my player model. The reason I had to add this was sometimes when you hit play the player would start at a weird position depending on where the headset was at the beginning. In the screen shot you can see use position tracking as not being checked in the inspector, that is an error. Please keep it selected to prevent screen tearing in the headset

enter image description here

Here is the code for the changing position of player when in game:

public class VRPositionChange : MonoBehaviour
{
    public Transform resetPos;
    private Transform parent;
    private void Awake()
    {
        // create a new object and make it parent of this object
        parent = gameObject.GetComponentInParent<Transform>();
    }

    // Update is called once per frame
    private void Update()
    {


        if (Input.GetKeyDown(KeyCode.Space))
        {

            // reset parent objects position
           parent.position = resetPos.position;
        }
    }
}
Afroca
  • 115
  • 11
  • @derHugo the value is only assigned once. It is designed to be a re-spawn location that can be set in the editor based on the location of the relocation object. I am still pretty new to unity. Thanks for the feedback though – Afroca Jul 24 '19 at 18:28
  • yes but you assign `parent.position` twice in your two lines. Note that the `CameraPlayer.localPosition` is a `Vector3` which is a struct (value type - **not a reference type**). – derHugo Jul 24 '19 at 18:31
  • @derHugo what that line does is it sets the parent to the current location of the center eye camera (For the oculus) then it resets it back to the respawn location. That way the local position of the camera is still relative to the global location of the camera rig. Without the 2 lines the player model will be offset by a lot based on where you were before respawn. – Afroca Jul 24 '19 at 18:33
  • 1
    what I'm trying to say is this line `parent.position = CameraPlayer.localPosition ;` could be skipped since right after it you anyway assign a different position .. so this line does nothing actually. – derHugo Jul 24 '19 at 18:35
  • I see what you're talking about. Ill remove it. – Afroca Jul 24 '19 at 18:44