【发布时间】:2016-04-18 15:50:49
【问题描述】:
我正在尝试在 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));
}
}
}
}
通过与这些类似的计算,我已经能够通过修改 x 和 z 值在水平水平上相应地移动十字准线,但 y 轴似乎是最大的问题。 Y 轴似乎总是收到太低的值。 十字线元素作为 Unity 中 CenterEyeAnchor 相机对象的子元素放置。
所以问题是:计算目标点位置的方法是否正确,因为我一直在努力做到这一点? 我必须根据新的目标点值对十字准线位置进行什么样的计算,以使其行为与食指运动相应?值的比例因子?
【问题讨论】:
-
我对 oculus 和跳跃非常熟悉,但除非您包含显示对象设置的某种屏幕截图,否则几乎不可能提供帮助。目前绝对不可能“知道任何东西在哪里”。
标签: c# unity3d leap-motion