Search Unity

Instantaneous Attach Transforms not lining up correctly

Discussion in 'AR/VR (XR) Discussion' started by flipwon, Jun 19, 2020.

  1. flipwon

    flipwon

    Joined:
    Dec 29, 2016
    Posts:
    179
    I seem to be having an issue when setting an XR Grab Interactable to Instantaneous. The Attach Transform seems to get messed up and turns into some sort of middle ground between the object and the selected attach transform or something...

    Any idea why this is or how to fix it?
     
  2. banaans

    banaans

    Joined:
    Feb 18, 2019
    Posts:
    2
    Did you ever resolve this issue? I'm facing it as well.

    Edit: I was able to solve it by fixing the setting the origin to geometry in Blender for the model. Object > Set Origin > Set Origin to Geometry
     
    Last edited: Nov 12, 2020
  3. redcurry79

    redcurry79

    Joined:
    Oct 26, 2020
    Posts:
    36
    I'm seeing this problem as well. It could be a bug. I don't think we should be required to change the model's Origin. After all, it works fine when the Movement Type is Kinematic (but with Kinematic the object being grabbed seems to wobble a bit---it doesn't feel good).
     
  4. mattouBatou

    mattouBatou

    Joined:
    Sep 2, 2016
    Posts:
    20
    Bumping as still seeing this issue with latest XR Interaction Toolkit.
     
  5. mattouBatou

    mattouBatou

    Joined:
    Sep 2, 2016
    Posts:
    20
    @redcurry79 It definitely looks like a minor bug to me. Just an oversight I think, the below lines where not change after adding the movementType feature most likely?

    So looking at XRGrabInteractable.cs in
    UpdateInteractorLocalPose() line 603:
    Code (CSharp):
    1. var attachOffset = m_Rigidbody.worldCenterOfMass - attachPosition;
    the Rigidbody.worldCenterOfMass is used. Obviously if the movementType of a grabbable object is set to Instantaneous, the Rigidbody is disabled while the interaction takes place.

    I could be barking up the wrong tree as I'm new to the XR Interaction Toolkit and Unity XR AND VR development in general but I'd think something like this should work:

    Code (CSharp):
    1. if (m_CurrentMovementType == MovementType.Instantaneous)
    2. {
    3.     attachOffset = m_TargetWorldPosition - attachPosition;
    4. }
    Immediatley after the previous line where attachOffset var was declared. I can't test it since whenever you hit run in Unity Editor, the script is reloaded/reset so no changes to the XRITK scripts work at runtime.
     
    Last edited: May 12, 2021
    redcurry79 likes this.
  6. mattouBatou

    mattouBatou

    Joined:
    Sep 2, 2016
    Posts:
    20
    I found a solution for this that works for me!

    Make a new C# script with the following code and use it instead of the usual XRGrabInteractable.cs component.

    Just be sure to set Movement Type field to Instantaneous and add the Attach Transform.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.XR.Interaction.Toolkit;
    3.  
    4. public class XRGrabInteractableFixedAttachTransform : XRGrabInteractable
    5. {
    6.     private bool isGrabbed = false;
    7.     protected override void OnSelectEntered(SelectEnterEventArgs args)
    8.     {
    9.         isGrabbed = true;
    10.         base.OnSelectEntered(args);
    11.     }
    12.  
    13.     protected override void OnSelectExited(SelectExitEventArgs args)
    14.     {
    15.         isGrabbed = false;
    16.         base.OnSelectExited(args);
    17.     }
    18.  
    19.     public override void ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase updatePhase)
    20.     {
    21.         base.ProcessInteractable(updatePhase);
    22.  
    23.         if (isGrabbed && movementType == MovementType.Instantaneous)
    24.         {
    25.             var attachOffset = transform.position - attachTransform.position;
    26.             transform.position = selectingInteractor.transform.position + attachOffset;
    27.             transform.rotation = Quaternion.Inverse(Quaternion.Inverse(transform.rotation) * attachTransform.rotation * Quaternion.Inverse(selectingInteractor.transform.rotation));
    28.         }
    29.     }
    30. }
    This fix works with:
    XR Interaction Toolkit 1.0.0-pre.3

    It may not work with earlier versions due to renaming of the OnSelectEntered & OnSelectExited methods but it's just a matter of using the correct names for earlier version of the XRITK.
     
    Last edited: May 14, 2021
    redcurry79 likes this.