Unity Final VR IK(资产)将人锁定在坐姿 [英] Unity Final VR IK (Asset) lock person in sitting position

查看:567
本文介绍了Unity Final VR IK(资产)将人锁定在坐姿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在为有辅助功能限制的人制作游戏。我遇到了将播放器模型锁定在坐姿的问题。如果用户不在房间中居中,则将播放器模型拉向某个方向。我想将玩家模型锁定在座位上,并且只允许手臂运动和头部旋转,而不能使用HMD在游戏中倾斜或移动。

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.

由于我使用的是最终VR IK资产,因此我尝试使用其演示在VR中的坐姿,无法让玩家自然坐下。我不确定如何编程或设置限制来做到这一点。

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.

编辑:为简化我的问题。您如何锁定oculus rift HMD仅允许旋转而不允许位置跟踪。

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

推荐答案

我知道了如何锁定将HMD放入,仅允许旋转,而不允许位置跟踪。要添加坐姿,只需使用坐着的身体动画即可。我做了两件事。首先,我向OVRCameraRig脚本添加了一行代码:

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;

这是在RaiseUpdatedAnchorsEvent()之前完成的;在UpdateAnchors()方法中的第260行周围进行调用。这是做什么的,它锁定了头部的位置,只允许头部旋转。

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.

我做的第二件事是根据@derHugo答案之一写了一个头部重定位脚本我的其他问题。这是当按下空格键时它将移动整个OVRCameraRig位置。 要使其正常工作,必须在OVRC​​ameraRig上有一个父级。在下面的屏幕快照中,您可以看到CameraParent对象为父级。我使用球体作为重定位对象,该球体放置在播放器模型头部的中间。我必须添加此选项的原因有时是在您点击播放时,播放器会根据耳机开始的位置在一个奇怪的位置开始播放。 在屏幕截图中,您可以看到在检查器中未检查使用位置跟踪,这是一个错误。请保持选中状态以防止耳机屏幕破裂

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

这是游戏中玩家改变位置的代码:

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;
        }
    }
}

这篇关于Unity Final VR IK(资产)将人锁定在坐姿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆