Skip to content

Commit 832b2f0

Browse files
committed
Release orb when either hand is moved away from orb S5
1 parent 21a7ccc commit 832b2f0

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

Assets/Scenes/5 Light.unity

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ MonoBehaviour:
320320
orbPrefab: {fileID: 2942899355471292517, guid: 09f3b4ed6cad1c84b91c3f6d48253d47, type: 3}
321321
sceneContainer: {fileID: 807878341}
322322
poseHoldDuration: 0.2
323+
handDistanceFromSphereStopTracking: 0.1
323324
--- !u!4 &840585900
324325
Transform:
325326
m_ObjectHideFlags: 0

Assets/Scripts/5 Light/LightSceneManager.cs

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ public class LightSceneManager : MonoBehaviour
1010
public GameObject sceneContainer;
1111
[Tooltip("How long the pose must be held for before orb is spawned")]
1212
public float poseHoldDuration = 0f;
13+
[Tooltip("How far the hand should be away from sphere to stop it following hand")]
14+
public float handDistanceFromSphereStopTracking = 0.5f;
1315
private GameObject currentOrbPrefab;
1416
private bool leftHandPoseDetected = false;
1517
private bool rightHandPoseDetected = false;
1618
private MainSceneManager mainSceneManager;
1719
private bool trackOrbToHands = false;
20+
private MeshRenderer currentOrbMesh;
1821

1922

2023
private void Start()
@@ -28,15 +31,63 @@ private void Update()
2831
{
2932
return;
3033
}
31-
Vector3 centerPoint = GetCenterPointBetweenHands();
32-
currentOrbPrefab.transform.position = centerPoint;
34+
Vector3? centerPoint = GetCenterPointBetweenHands();
35+
if (centerPoint != null)
36+
{
37+
38+
currentOrbPrefab.transform.position = (Vector3)centerPoint;
39+
CheckIfHandsRemovedFromOrb((Vector3)centerPoint);
40+
}
41+
42+
}
43+
44+
/* When user moves their hands away from orb, stop tracking it with hands and leave in position */
45+
private void CheckIfHandsRemovedFromOrb(Vector3 centerPoint)
46+
{
47+
if (currentOrbMesh == null || centerPoint == null)
48+
{
49+
return;
50+
}
51+
Hand leftHand = mainSceneManager.ultraleapService.GetHand(Chirality.Left);
52+
Hand rightHand = mainSceneManager.ultraleapService.GetHand(Chirality.Right);
53+
float leftHandDistanceFromOrbEdge = 0;
54+
float rightHandDistanceFromOrbEdge = 0;
55+
56+
if (leftHand != null && leftHand.PalmPosition != null && centerPoint != null && currentOrbMesh != null)
57+
{
58+
leftHandDistanceFromOrbEdge = GetHandDistanceFromOrbEdge(leftHand.PalmPosition, (Vector3)centerPoint, currentOrbMesh);
59+
if (leftHandDistanceFromOrbEdge >= handDistanceFromSphereStopTracking)
60+
{
61+
OnPoseLost("left");
62+
}
63+
}
64+
if (rightHand != null && rightHand.PalmPosition != null && centerPoint != null && currentOrbMesh != null)
65+
{
66+
67+
rightHandDistanceFromOrbEdge = GetHandDistanceFromOrbEdge(rightHand.PalmPosition, (Vector3)centerPoint, currentOrbMesh);
68+
if (rightHandDistanceFromOrbEdge >= handDistanceFromSphereStopTracking)
69+
{
70+
OnPoseLost("right");
71+
}
72+
}
73+
}
74+
75+
private float GetHandDistanceFromOrbEdge(Vector3 handPosition, Vector3 centre, MeshRenderer mesh)
76+
{
77+
float distanceBetweenHandsAndOrbCentre = Vector3.Distance(handPosition, currentOrbPrefab.transform.position);
78+
float orbRadius = currentOrbMesh.bounds.extents.x;
79+
return distanceBetweenHandsAndOrbCentre - orbRadius;
3380
}
3481

3582

36-
private Vector3 GetCenterPointBetweenHands()
83+
private Vector3? GetCenterPointBetweenHands()
3784
{
3885
Hand leftHand = mainSceneManager.ultraleapService.GetHand(Chirality.Left);
3986
Hand rightHand = mainSceneManager.ultraleapService.GetHand(Chirality.Right);
87+
if (leftHand == null || rightHand == null)
88+
{
89+
return null;
90+
}
4091
Vector3 handCenterPoint = (rightHand.PalmPosition + leftHand.PalmPosition) / 2;
4192
return handCenterPoint;
4293
}
@@ -46,7 +97,8 @@ public void OnPoseDetect(string hand)
4697
if (hand == "left")
4798
{
4899
leftHandPoseDetected = true;
49-
} else if (hand == "right")
100+
}
101+
else if (hand == "right")
50102
{
51103
rightHandPoseDetected = true;
52104
}
@@ -61,6 +113,7 @@ private IEnumerator DebouncePoseDetect()
61113
{
62114
yield return new WaitForSeconds(poseHoldDuration);
63115
currentOrbPrefab = Instantiate(orbPrefab, sceneContainer.transform);
116+
currentOrbMesh = currentOrbPrefab.transform.GetChild(0).GetChild(0).GetComponent<MeshRenderer>();
64117
trackOrbToHands = true;
65118
}
66119

@@ -80,6 +133,7 @@ public void OnPoseLost(string hand)
80133
if (!leftHandPoseDetected || !rightHandPoseDetected)
81134
{
82135
trackOrbToHands = false;
136+
currentOrbMesh = null;
83137
StopCoroutine(DebouncePoseDetect());
84138
}
85139
}

ProjectSettings/ProjectSettings.asset

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ PlayerSettings:
134134
vulkanEnableCommandBufferRecycling: 1
135135
loadStoreDebugModeEnabled: 0
136136
bundleVersion: 0.1
137-
preloadedAssets: []
137+
preloadedAssets:
138+
- {fileID: 11400000, guid: 09c38c41cf5458045bdfcca884d6e65c, type: 2}
139+
- {fileID: -6261776379101851301, guid: 23a88644da724b5438abbf82bcf60a42, type: 2}
138140
metroInputSource: 0
139141
wsaTransparentSwapchain: 0
140142
m_HolographicPauseOnTrackingLoss: 1

0 commit comments

Comments
 (0)