[英]LeapMotion + Unity: Moving an object in a 3D world based on the angle of a finger
我正在尝试在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相机对象的子元素。
因此,问题是:我一直在尝试计算目标点位置的方法正确吗? 我必须根据新的目标点值对十字线位置进行什么样的计算,以使其与食指的移动相对应? 比例因子的值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.