2017-06-21 30 views
0

我试图在我的Unity项目中实现类似于HTC Vive控制器的飞跃运动功能。我想从食指上产生一个激光指针,并将Vive的房间传送到激光位置(如同控制器一样)。问题在于最新的飞跃(orion)文件,目前还不清楚。任何想法如何做到这一点?更一般的情况是,我们考虑使用HandController,但我们不明白在哪里添加脚本组件。 谢谢!Htc Vive +作为控制器的飞跃运动

回答

0

目前还不清楚您所遇到的问题是根据您的场景获取手部数据还是使用该手部数据。

如果您只是试图在场景中获取手部数据,则可以从Unity SDK的示例场景之一复制预制件。如果您尝试将Leap集成到已经设置了VR装备的现有场景中,请查看the core Leap components上的文档,以了解需要开始获取Hand数据的部分。 LeapServiceProvider必须位于场景中的某个位置才能接收手形数据。

只要你有一个LeapServiceProvider的地方,你可以从大跃进运动从任何脚本访问手,随时随地。因此,从指数指尖得到一个射线,只是弹出这个脚本任何老地方:

using Leap; 
using Leap.Unity; 
using UnityEngine; 

public class IndexRay : MonoBehaviour { 
    void Update() { 
    Hand rightHand = Hands.Right; 
    Vector3 indexTipPosition = rightHand.Fingers[1].TipPosition.ToVector3(); 
    Vector3 indexTipDirection = rightHand.Fingers[1].bones[3].Direction.ToVector3(); 
    // You can try using other bones in the index finger for direction as well; 
    // bones[3] is the last bone; bones[1] is the bone extending from the knuckle; 
    // bones[0] is the index metacarpal bone. 

    Debug.DrawRay(indexTipPosition, indexTipDirection, Color.cyan); 
    } 
} 

对于它的价值,该指数指尖方向可能不会足够稳定,做你想做的。更可靠的策略是通过手部的指节关节从相机投下一条线(或理论上“相对于相机恒定偏移的肩部位置”):

using Leap; 
using Leap.Unity; 
using UnityEngine; 

public class ProjectiveRay : MonoBehaviour { 

    // To find an approximate shoulder, let's try 12 cm right, 15 cm down, and 4 cm back relative to the camera. 
    [Tooltip("An approximation for the shoulder position relative to the VR camera in the camera's (non-scaled) local space.")] 
    public Vector3 cameraShoulderOffset = new Vector3(0.12F, -0.15F, -0.04F); 

    public Transform shoulderTransform; 

    void Update() { 
    Hand rightHand = Hands.Right; 
    Vector3 cameraPosition = Camera.main.transform.position; 
    Vector3 shoulderPosition = cameraPosition + Camera.main.transform.rotation * cameraShoulderOffset; 

    Vector3 indexKnucklePosition = rightHand.Fingers[1].bones[1].PrevJoint.ToVector3(); 
    Vector3 dirFromShoulder = (indexKnucklePosition - shoulderPosition).normalized; 

    Debug.DrawRay(indexKnucklePosition, dirFromShoulder, Color.white); 

    Debug.DrawLine(shoulderPosition, indexKnucklePosition, Color.red); 
    } 
} 
相关问题