Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LeapMotion+;统一:基于手指角度在三维世界中移动对象_C#_Unity3d_Leap Motion - Fatal编程技术网

C# LeapMotion+;统一:基于手指角度在三维世界中移动对象

C# LeapMotion+;统一:基于手指角度在三维世界中移动对象,c#,unity3d,leap-motion,C#,Unity3d,Leap Motion,我试图在Unity中创建一个瞄准系统,食指用来控制十字线。游戏正在使用Oculus进行,Leap Motion安装在Oculus耳机上 我试图根据食指的角度计算十字线的位置,并根据给定的距离绘制光线。我还试着根据食指的方向和给定的距离计算十字线的位置,如下所示: Vector3 targetPoint = direction * direction; 以下是我尝试过的: void Start () { crossHair = GameObject.Find("Crosshair Com

我试图在Unity中创建一个瞄准系统,食指用来控制十字线。游戏正在使用Oculus进行,Leap Motion安装在Oculus耳机上

我试图根据食指的角度计算十字线的位置,并根据给定的距离绘制光线。我还试着根据食指的方向和给定的距离计算十字线的位置,如下所示:

Vector3 targetPoint = direction * direction;
以下是我尝试过的:

void Start () {
    crossHair = GameObject.Find("Crosshair Component");
    myCamera = GameObject.Find("CenterEyeAnchor");
    target = crossHair.transform;
    controller = new Controller(); 
    indexFinger = new Finger();

    void Update () {

    crossHair.transform.position = myCamera.transform.position;
    frame = controller.Frame();
    List<Hand> handList = new List<Hand>();
    for (int h = 0; h < frame.Hands.Count; h++)
    {
        Hand leapHand = frame.Hands[h];
        handList.Add(leapHand);
    }

    if (handList != null && frame.Hands.Count > 0) {
        indexFinger = frame.Hands[0].Fingers[(int)Finger.FingerType.TYPE_INDEX];
        if (indexFinger.IsExtended)
        {
            Vector3 fingerTipPos = indexFinger.TipPosition.ToUnityScaled();

            Vector3 originAngle = indexFinger.TipPosition.ToUnityScaled();
            Vector3 targetAngle = crossHair.transform.position;
            float distance = 1; 

            Vector3 direction = indexFinger.Direction.ToUnityScaled();
            Ray rayToTest = new Ray(originAngle, targetAngle);
            Vector3 targetPoint = rayToTest.GetPoint(distance);

            //Problem is here. How should these targetPoint values be used to calculate correct position for the crosshair?
            crossHair.transform.position = new Vector3(crossHair.transform.position.x + (targetPoint.x), y,
                                                    crossHair.transform.position.z + (targetPoint.z));
        }


    }
}
void Start(){
crossHair=GameObject.Find(“crossHair组件”);
myCamera=GameObject.Find(“CenterEyeAnchor”);
目标=crossHair.transform;
控制器=新控制器();
indexFinger=新手指();
无效更新(){
crossHair.transform.position=myCamera.transform.position;
frame=controller.frame();
List handList=新列表();
对于(int h=0;h0){
indexFinger=frame.Hands[0]。Fingers[(int)Finger.FingerType.TYPE_INDEX];
if(indexFinger.IsExtended)
{
Vector3 fingerTipPos=indexFinger.TipPosition.ToUnityScaled();
Vector3 originAngle=indexFinger.tiposition.ToUnityScaled();
Vector3 targetAngle=crossHair.transform.position;
浮动距离=1;
Vector3方向=indexFinger.direction.ToUnityScaled();
光线测试=新光线(原始角度、目标角度);
Vector3目标点=光线测试点(距离);
//问题就在这里。应该如何使用这些目标点值来计算十字线的正确位置?
crossHair.transform.position=新矢量3(crossHair.transform.position.x+(targetPoint.x),y,
crossHair.transform.position.z+(targetPoint.z));
}
}
}
}

通过类似的计算,我可以通过修改x和z值在水平面上相应地移动十字线,但y轴似乎是最大的问题。Y轴似乎总是接收太低的值。 十字线元素作为Unity中CenterEyeAnchor摄影机对象的子元素放置

所以问题是:计算目标点位置的方法是否正确,就像我一直试图做到的那样?
根据新的目标点值,我必须对十字光标位置进行什么样的计算,以使其与食指移动相应?值的比例因子?

项目设置和当前附着对象位置的图片


我对oculus和leap非常熟悉,但除非您包含某种显示对象设置的屏幕截图,否则几乎无法提供帮助。现在绝对不可能“知道任何东西在哪里”。