0
我正在嘗試在Unity中創建瞄準系統,其中食指正用於控制十字線。 Oculus正在玩遊戲,而Leap Motion則安裝在Oculus耳機上。LeapMotion + Unity:基於手指角度在3D世界中移動對象
我試圖根據食指的角度計算十字準線的位置,並根據給定的距離繪製一條射線。我也試着計算只是基於食指的方向和給出這樣的距離十字位置:
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公司和熟悉的飛躍,但它幾乎是不可能的幫助,除非你有某種形式的屏幕截圖顯示的對象設置的。目前「知道什麼是什麼」是絕對不可能的。 – Fattie