Search Unity

Question Flexible Grab Point

Discussion in 'XR Interaction Toolkit and Input' started by AnahidE5, Apr 21, 2022.

  1. AnahidE5

    AnahidE5

    Joined:
    Jan 10, 2022
    Posts:
    40
    I am using XR Grab Interactable and when I pick an object up, either with ray or a collider on the hand, it picks it up either from the middle or from the attach transform (like an empty gameobject) that I manually set. Is it possible to grab an object from wherever the ray hits it or the hand collides with it?
    I also noticed that when I grab something, it auto rotates the object based on the hand. I want the object to track the rotation changes, but I don't want it to reset the rotation every time I pick it up. In other words, i want to be able to grab and rotate the object, let it go (it's kinematic), and pick it up while it holds the current rotation so I can rotate it again or more or do whatever else. I feel like there should be a pre-made grab method for this but I can't find it. I don't even know what to Google to find some guidance on this. Any help would be much appreciated.
     
    DT-007 likes this.
  2. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    275
    Hi @AnahidE5,
    We are currently working on support for this in the next minor release of the XR Interaction Toolkit (2.1.0). I don't have an exact date on the release of 2.1.0, but it will likely be in the next couple of months.
     
  3. AnahidE5

    AnahidE5

    Joined:
    Jan 10, 2022
    Posts:
    40
    Hi Dave. I tested 2.1.0 but I can't figure out how to enable the support for what we talked about above. Is it related to the "Use dynamic attach" setting and if it is, how can i make it work? I tried different settings and still the rotation is automatically changed every time i grab the object. Thanks.
     
  4. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    231
    With 2.1.0 of XRI, enable Use Dynamic Attach in the Inspector window of your XR Grab Interactable. By default, Match Position and Match Rotation will both already be enabled which should allow the position and rotation to be set so it doesn't cause any initial movement when you grab it.

    Note that if you are using an XR Ray Interactor with Force Grab enabled, the dynamic attach pose will be the same as the static attach pose on the XR Grab Interactable instead of being based on the hit position. This is because we assume if you want to bring the object to your hand, it should not stay at a far distance which is what would happen if the dynamic attach calculated the offset relative to that attach position. If you want to keep the object where it is, you'll need to disable Force Grab on your XR Ray Interactors.
     
  5. AnahidE5

    AnahidE5

    Joined:
    Jan 10, 2022
    Posts:
    40
    Thanks a lot for the explanation. What about having it come close but keep the original rotation? I disabled force grab, enabled Use Dynamic Attach and Match rotation thinking the position will change but the object will keep the rotation but it also keeps its position instead of moving to the hand. Is there another setting overriding that? Thanks again.
     
  6. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    231
    At the moment, the XR Grab Interactable ignores the Match Position and Match Rotation when the interactor grabbing it is an XR Ray Interactor with Force Grab enabled. If you want to change that, you'll need to create a new script that derives from
    XRGrabInteractable
    and override the InitializeDynamicAttachPose method, copy the code from the base class and remove the early return check for
    interactor is XRRayInteractor rayInteractor && rayInteractor.useForceGrab
    . You'll have to change some of the variables to use the property name instead of the field name when you copy-paste. Then you can disable Match Position and keep Match Rotation enabled and it will achieve what you want.

    I made a task for our team to look into either updating the API to make the conditions easier to override, or modify the method so it allows you to keep the rotation but ignores the value of Match Position when Force Grab is enabled. Our assumption was that if Force Grab was enabled, users would want it to always go to the fixed static attach pose set on the Interactor, but it sounds like that's not the case. We'll try to make that update before the final 2.1.0 release.
     
    AnahidE5 likes this.
  7. DishwashaBubble

    DishwashaBubble

    Joined:
    Oct 19, 2023
    Posts:
    39
    Any update on this? Did the force grab + dynamic attach end up becoming an optional feature? I would like to have both. Also in your instructions I am not sure what you mean by changing variables to use property name instead of the field name.
     
  8. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    231
    The change I mentioned made it into the 2.1.1 release, so you shouldn't need to override
    InitializeDynamicAttachPose
    like I mentioned in my earlier post to get that desired behavior:
    As for the copy-paste thing I was talking about, I meant that if you copied the method into a custom derived class to tweak part of it, you could copy the entire contents but you would need to replace the private fields like
    m_MatchAttachPosition
    with public properties like
    matchAttachPosition
    in your derived class for it to compile.
     
    DishwashaBubble likes this.