11

玩转Oculus Quest +Unity开发004-实现手柄抓握和对场景中物体的互动

 3 years ago
source link: https://zhuanlan.zhihu.com/p/92075692
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

玩转Oculus Quest +Unity开发004-实现手柄抓握和对场景中物体的互动

苹果粉丝,摄影迷,心理学爱好者

在上一部分的内容中,我们可以在场景中看到手柄了,但是仍然不能直接进行交互。

在这一部分的内容中,我们将实际实现交互。

Step1.修复bug,可以让用户跟方块靠的更近

在Hierarchy试图中选中OVRPlayerController,然后在Inspector试图中的Character Controller属性中更改Radius为0.3或其它合适的数字

Step2.美化场景

1.使用Probuilder的vertex color更改物体的材质颜色

2.更改天空盒设置

Step3.实现手柄抓握的方式1

1.在Project试图的Assets/Oculus/SampleFramework/Core/AvatarGrab/Prebabs中找到LocalAvatarWithGrab

在Hierarchy视图中点开,可以看到其中包含了AvatarGrabberLeft,AvatarGrabberRight和OVRCameraRig三个Prefab预设体。

2.隐藏之前添加的OVRPlayerController这个预设体。

3.对要抓取的物体添加box collider

选中场景中要抓取的物体,在Inspector视图中添加Box Collider组件和Rigidbody组件,保持默认设置就好。继续在Inspector视图中添加OVRGrabbable组件

通过以上设置,我们就实现了在场景中使用手柄抓握物体进行交互。

但是这种方式有一个弊端,那就是作为玩家是不能自由移动的,只适合于坐式原地体验。

Step4. 实现手柄抓握的方式2

1.隐藏/删除刚才添加的LocalAvatarWithGrab对象

2.在场景中添加OVRPlayerController对象

3.在Hierarchy视图中找到OVRPlayerController下的OVRCameraRig/TrackingSpace/LeftHandAnchor,点击,

(1)在Inspector视图中添加一个OVRGrabber组件。

(2)手动将Controller设置为L Touch。

(3)勾选Parent Held Object

(4)勾选Rigidbody组件的Is Kinematic属性,取消勾选Use Gravity属性

4.右键单击LeftHandAnchor,添加一个新的Sphere子对象,

(1)删除它的Mesh filter和Mesh Renderer,只保留Transform和Sphere Collider组件。

(2)更改Sphere collider的Radius属性为0.05(总之要远小于默认值)。

(3)勾选Is Trigger

5.在OVR Grabber(Script)这个组件中,

(1)将Grab Volumes的Size属性设置为1,

(2)将刚刚添加的Sphere对象拖到Element 0后面的方框中。

(3)此外还需要把Grip Transform的属性设置为LeftHandAnchor

6.接着对RightHandAnchor做类似操作,只是注意要将Controller属性设置为R Touch,另外相关属性为RightHandAnchor。

7.在Project视图中,Oculus/VR/Meshes/OculusTouchForQuestAndRiftS,找到OculusTouchForQuestAndRiftS_Left和OculusTouchForQuestAndRiftS_Right

分别拖动为LeftHandAnchor和RightHandAnchor的子对象。

8.点击Build and run测试,就可以体验使用手柄抓握物体进行交互的操作。

Step5.在场景中添加更多物体(直接复制当前的方块,免得又要重新进行相关的组件设置),以便更好的测试~

具体操作请参考视频(微信公众号vrlife,B站赛隆网)

相关示例项目后续会上传github(https://github.com/eseedo/AR-VRCourse)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK