@@ -44,6 +44,7 @@ public class HandDraggable : MonoBehaviour,
4444 private bool isDragging ;
4545 private bool isGazed ;
4646 private Vector3 objRefForward ;
47+ private Vector3 objRefUp ;
4748 private float objRefDistance ;
4849 private Quaternion gazeAngularOffset ;
4950 private float handRefDistance ;
@@ -117,6 +118,7 @@ public void StartDragging()
117118 objRefDistance = Vector3 . Magnitude ( gazeHitPosition - pivotPosition ) ;
118119
119120 Vector3 objForward = HostTransform . forward ;
121+ Vector3 objUp = HostTransform . up ;
120122
121123 // Store where the object was grabbed from
122124 objRefGrabPoint = mainCamera . transform . InverseTransformDirection ( HostTransform . position - gazeHitPosition ) ;
@@ -125,10 +127,12 @@ public void StartDragging()
125127 Vector3 handDirection = Vector3 . Normalize ( handPosition - pivotPosition ) ;
126128
127129 objForward = mainCamera . transform . InverseTransformDirection ( objForward ) ; // in camera space
130+ objUp = mainCamera . transform . InverseTransformDirection ( objUp ) ; // in camera space
128131 objDirection = mainCamera . transform . InverseTransformDirection ( objDirection ) ; // in camera space
129132 handDirection = mainCamera . transform . InverseTransformDirection ( handDirection ) ; // in camera space
130133
131134 objRefForward = objForward ;
135+ objRefUp = objUp ;
132136
133137 // Store the initial offset between the hand and the object, so that we can consider it when dragging
134138 gazeAngularOffset = Quaternion . FromToRotation ( handDirection , objDirection ) ;
@@ -197,7 +201,8 @@ private void UpdateDragging()
197201 else
198202 {
199203 Vector3 objForward = mainCamera . transform . TransformDirection ( objRefForward ) ; // in world space
200- draggingRotation = Quaternion . LookRotation ( objForward ) ;
204+ Vector3 objUp = mainCamera . transform . TransformDirection ( objRefUp ) ; // in world space
205+ draggingRotation = Quaternion . LookRotation ( objForward , objUp ) ;
201206 }
202207
203208 // Apply Final Position
0 commit comments