Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Unable to grab object with hands tracking

Discussion in 'VR' started by D27, Jul 11, 2021.

  1. D27

    D27

    Joined:
    Sep 4, 2017
    Posts:
    2
    Hi,
    I try to use the hand tracking for Quest.
    It works well for detection of hands.
    I try to grab a cube with OVRGrabber and OVR Grabbable but it doesn't work.
    Here are screens for the R_hand and the grabbable cube.
    Do you know how to do ?
    I tried to find a tutorial with this version but found nothing.
    Thanks a lot.





     
  2. SpectreXR

    SpectreXR

    Joined:
    Dec 1, 2021
    Posts:
    5
    Hello. Valem made a short tutorial on this a long time ago. You will need to make some minor changes since the oculus integration has been updated since, but most of it is still the same:

     
  3. ramya1304

    ramya1304

    Joined:
    Sep 6, 2019
    Posts:
    1
    You have to attach a HandGrabber script to your Hand. Here, I used fingers pinching strength to grab the objects. When index pinching strength greater than the threshold, the grab begins else grab ends


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using OculusSampleFramework;
    6.  
    7. public class HandGrabber : OVRGrabber
    8. {
    9.     public OVRHand hand;
    10.     public float pinchTreshold = 0.7f;
    11.  
    12.     public Text handDetails;
    13.  
    14.     public Text IndexText;
    15.     public Text RingText;
    16.     public Text MiddleText;
    17.     public Text PinkyText;
    18.     public Text MaxText;
    19.     public Text ThumbText;
    20.  
    21.     private Rigidbody rb;
    22.  
    23.     // Start is called before the first frame update
    24.    protected override void Start()
    25.     {
    26.         base.Start();
    27.         //hand =  hand.GetComponent<OVRHand>();
    28.         if(m_grabbedObj)
    29.         {
    30.             rb = m_grabbedObj.GetComponent<Rigidbody>();
    31.         }
    32.        
    33.     }
    34.  
    35.     public override void Update()
    36.     {
    37.         base.Update();
    38.        
    39.         CheckIndexPinch();
    40.        
    41.     }
    42.  
    43.     public void CheckIndexPinch()
    44.     {
    45.         float pinchIndexStrength = GetComponent<OVRHand>().GetFingerPinchStrength(OVRHand.HandFinger.Index);
    46.  
    47.        
    48.  
    49.         float pinchRingStrength = GetComponent<OVRHand>().GetFingerPinchStrength(OVRHand.HandFinger.Ring);
    50.  
    51.         float pinchPinkyStrength = GetComponent<OVRHand>().GetFingerPinchStrength(OVRHand.HandFinger.Pinky);
    52.  
    53.      
    54.         IndexText.text = pinchIndexStrength.ToString();
    55.         RingText.text = pinchRingStrength.ToString();
    56.         //MiddleText.text = pinchMiddleStrength.ToString();
    57.         PinkyText.text = pinchPinkyStrength.ToString();
    58.        
    59.  
    60.         bool isPinching = pinchIndexStrength > pinchTreshold;
    61.      
    62.         if (!m_grabbedObj && isPinching && m_grabCandidates.Count > 0 )
    63.             GrabBegin();
    64.         else if (m_grabbedObj && !isPinching)
    65.             GrabEnd();
    66.  
    67.         float pinchMaxStrength = GetComponent<OVRHand>().GetFingerPinchStrength(OVRHand.HandFinger.Max);
    68.         MaxText.text = pinchMaxStrength.ToString();
    69.         float pinchThumbStrength = GetComponent<OVRHand>().GetFingerPinchStrength(OVRHand.HandFinger.Thumb);
    70.         ThumbText.text = pinchThumbStrength.ToString();
    71.  
    72.     }
    73.  
    74.     protected override void GrabBegin()
    75.     {
    76.         base.GrabBegin();
    77.         handDetails.text = transform.name;
    78.        
    79.         if (rb != null && rb.isKinematic == false)
    80.         {
    81.             rb.isKinematic = true;
    82.         }
    83.     }
    84.  
    85.     protected override void GrabEnd()
    86.     {
    87.         if(m_grabbedObj)
    88.         {
    89.             Vector3 lineraVelocity = (transform.position - m_lastPos) / Time.fixedDeltaTime;
    90.             Vector3 angularVelocity = (transform.eulerAngles - m_lastRot.eulerAngles) / Time.fixedDeltaTime;
    91.  
    92.             GrabbableRelease(lineraVelocity, angularVelocity);
    93.  
    94.         }
    95.         if (rb != null && rb.isKinematic == true)
    96.         {
    97.             rb.isKinematic = false;
    98.         }
    99.  
    100.         GrabVolumeEnable(true);
    101.     }
    102.  
    103.  
    104. }
     
    Manicksport likes this.