17 [Tooltip(
"Your Leap Hand Provider. Ensure the Pinch Locomotion script " +
18 "is set to execute before this provider in the 'Script Execution Order'")]
27 bool isLeftPinching, isRightPinching;
28 Vector3 rootA = Vector3.zero, rootB = Vector3.one;
29 Vector3 curA = Vector3.zero, curB = Vector3.one;
37 if (leftPinching && rightPinching) {
38 curA = left .GetPinchPosition();
39 curB = right.GetPinchPosition();
41 if (!isLeftPinching || !isRightPinching) {
45 }
else if (leftPinching) {
46 oneHandedPinchMove(left, isLeftPinching, isRightPinching,
47 ref rootA, ref curA, rootB, ref curB);
48 }
else if (rightPinching) {
49 oneHandedPinchMove(right, isRightPinching, isLeftPinching,
50 ref rootB, ref curB, rootA, ref curA);
52 curA = Vector3.Lerp(curA, rootA,
momentum);
53 curB = Vector3.Lerp(curB, rootB,
momentum);
55 isLeftPinching = leftPinching;
56 isRightPinching = rightPinching;
59 Vector3 pivot = ((rootA + rootB) / 2);
60 Vector3 translation = pivot - ((curA + curB) / 2);
61 Quaternion rotation = Quaternion.FromToRotation(Vector3.Scale(
new Vector3(1f,
horizontalRotation ? 0 : 1f, 1f), curB - curA),
63 float scale = (rootA - rootB).magnitude / (curA - curB).magnitude;
66 transform.root.position += translation;
70 Pose curTrans =
new Pose(transform.root.position, transform.root.rotation);
71 curTrans = curTrans.Pivot(rotation, pivot);
76 transform.root.position = ((transform.root.position - pivot) * scale) + pivot;
77 transform.root.localScale *= scale;
85 Vector3 residualMomentum = Vector3.zero;
87 void oneHandedPinchMove(
Hand thisHand,
bool thisIsPinching,
bool otherIsPinching,
88 ref Vector3 thisRoot, ref Vector3 thisCur, Vector3 otherRoot, ref Vector3 otherCur) {
89 thisCur = thisHand.GetPinchPosition();
91 if (!thisIsPinching || otherIsPinching) {
92 residualMomentum = otherCur - otherRoot;
95 otherCur = (otherRoot + (thisCur - thisRoot)) + residualMomentum;
The Hand class reports the physical characteristics of a detected hand.
float PinchDistance
The distance between the thumb and index finger of a pinch hand pose.
void RetransformFrames()
Retransforms hand data from Leap space to the space of the Unity transform. This is only necessary if...
override Frame CurrentFrame
Ensure this script is on your player object and set to execute before the LeapXRServiceProvider
LeapXRServiceProvider provider
The LeapXRServiceProvider expands on the standard LeapServiceProvider to account for the offset of th...
A position and rotation. You can multiply two poses; this acts like Matrix4x4 multiplication,...