Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved AttachPoint wrong when using Instantaneous movement type in XRGrabInteractable.

Discussion in 'XR Interaction Toolkit and Input' started by unitydreamer29, Dec 27, 2020.

  1. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    In the XRToolkit example WorldInteractionDemo scene, I changed the movement type of the Jigsaw to "Instantaneous" instead of "Kinematic".

    It seems that objects no longer attach correctly to the hands: XRGrabInteractableBug.JPG

    Also, when placing the object into a socket, the attach point will be incorrect. I already filed a bug through the editor, but was wondering if anyone has a fix for this.

    Thanks.
     
  2. mfuad

    mfuad

    Unity Technologies

    Joined:
    Jun 12, 2018
    Posts:
    334
    Hi @unitydreamer29, can you share the case # of your bug report so I can make sure we've received it? Thanks.
     
  3. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    Thanks @mfuad, just PM'd you.
     
  4. mikeNspired

    mikeNspired

    Joined:
    Jan 13, 2016
    Posts:
    81
    I know in the previous version. Instananeous used the rigidbody center position as the attachpoint. So I wrote a simple script that set the RigidBody.CenterOfMass to the attachment point on OnSelectEnter and reset it on OnSelectExit.
     
  5. brgishy

    brgishy

    Joined:
    Jul 9, 2013
    Posts:
    31
    That's a great workaround @mikeNspired. I ended up copying the whole XRGrabInteractable.cs file and renaming it BetterXRGrabInteractable.cs and changing a few lines of code to actually have the component look for it's AttachTransform.

    Code (CSharp):
    1.  
    2. // Added this function
    3. private Vector3 GetAttachPosition()
    4. {
    5.     return this.attachTransform != null ? this.attachTransform.position : this.m_Rigidbody.worldCenterOfMass;
    6. }
    7.  
    8. void PerformInstantaneousUpdate(XRInteractionUpdateOrder.UpdatePhase updatePhase)
    9. {
    10.     if (updatePhase == XRInteractionUpdateOrder.UpdatePhase.Dynamic ||
    11.         updatePhase == XRInteractionUpdateOrder.UpdatePhase.OnBeforeRender)
    12.     {
    13.         if (trackPosition)
    14.         {
    15.             // transform.position = m_TargetWorldPosition;  // Replaced this line with below 2 lines
    16.             var positionDelta = m_TargetWorldPosition - GetAttachPosition();
    17.             transform.position += positionDelta;
    18.         }
    19.         if (trackRotation)
    20.         {
    21.             transform.rotation = m_TargetWorldRotation;
    22.         }
    23.     }
    24. }
    25.  
    26. void PerformKinematicUpdate(XRInteractionUpdateOrder.UpdatePhase updatePhase)
    27. {
    28.     if (updatePhase == XRInteractionUpdateOrder.UpdatePhase.Fixed)
    29.     {
    30.         if (trackPosition)
    31.         {
    32.             // var positionDelta = m_TargetWorldPosition - m_Rigidbody.worldCenterOfMass;  // Replaced this line with the below line
    33.             var positionDelta = m_TargetWorldPosition - this.GetAttachPosition();
    34.          
    35.             m_Rigidbody.velocity = Vector3.zero;
    36.             m_Rigidbody.MovePosition(m_Rigidbody.position + positionDelta);
    37.         }
    38.         if (trackRotation)
    39.         {
    40.             m_Rigidbody.angularVelocity = Vector3.zero;
    41.             m_Rigidbody.MoveRotation(m_TargetWorldRotation);
    42.         }
    43.     }
    44. }
    45.  
    46. void PerformVelocityTrackingUpdate(float timeDelta, XRInteractionUpdateOrder.UpdatePhase updatePhase)
    47. {
    48.     if (updatePhase == XRInteractionUpdateOrder.UpdatePhase.Fixed)
    49.     {
    50.         // Do velocity tracking
    51.         if (trackPosition)
    52.         {
    53.             // Scale initialized velocity by prediction factor
    54.             m_Rigidbody.velocity *= k_VelocityPredictionFactor;
    55.          
    56.             // var posDelta = m_TargetWorldPosition - m_Rigidbody.worldCenterOfMass;  // Replaced this line with the below line
    57.             var posDelta = m_TargetWorldPosition - this.GetAttachPosition();
    58.          
    59.             var velocity = posDelta / timeDelta;
    60.  
    61.             if (!float.IsNaN(velocity.x))
    62.                 m_Rigidbody.velocity += velocity;
    63.         }
    64.  
    65.         // Do angular velocity tracking
    66.         if (trackRotation)
    67.         {
    68.             // Scale initialized velocity by prediction factor
    69.             m_Rigidbody.angularVelocity *= k_VelocityPredictionFactor;
    70.             var rotationDelta = m_TargetWorldRotation * Quaternion.Inverse(m_Rigidbody.rotation);
    71.             rotationDelta.ToAngleAxis(out var angleInDegrees, out var rotationAxis);
    72.             if (angleInDegrees > 180f)
    73.                 angleInDegrees -= 360f;
    74.  
    75.             if (Mathf.Abs(angleInDegrees) > Mathf.Epsilon)
    76.             {
    77.                 var angularVelocity = (rotationAxis * angleInDegrees * Mathf.Deg2Rad) / timeDelta;
    78.                 if (!float.IsNaN(angularVelocity.x))
    79.                     m_Rigidbody.angularVelocity += angularVelocity * k_AngularVelocityDamping;
    80.             }
    81.         }
    82.     }
    83. }
    84.  
    It would be nice if XR Interaction Toolkit were in GitHub and I could pull request this.

    Hope this helps!
     
    mikeNspired likes this.
  6. MarekLg

    MarekLg

    Joined:
    Jan 31, 2018
    Posts:
    26
    This Bug also extends to kinematic MovementType, when non-trigger-colliders are used.

    @mfuad Are there any updates on when this will be fixed? Thanks for your work!
     
  7. mfuad

    mfuad

    Unity Technologies

    Joined:
    Jun 12, 2018
    Posts:
    334
    No specific ETA to share. Please give our teams some time to catch up from the holidays. Thanks.
     
  8. Dobby95

    Dobby95

    Joined:
    Jun 1, 2020
    Posts:
    1
    Hello, Any updates on this subject? Instantaneous is the butter I seek but doesn't like the attach transform I have set. I tried @brgishy 's method but with no avail, possibly because of the tool kit version I am using 1.0.0 pre 3.

    anyway if anyone can shed some light on it that would be amazing :D
    cheers
     
  9. freso

    freso

    Joined:
    Mar 19, 2013
    Posts:
    73
  10. mattouBatou

    mattouBatou

    Joined:
    Sep 2, 2016
    Posts:
    20
    1.0.0-pre.3 does not have the fix for this as I have just this moment encountered the issue.
    @mfuad any updates on this? I switched from Oculus Integration due to the equivalent feature being completely broken, was very pleased to see XRITK work intuitively with the attachTransforms for snap-grabbing until I tried Instantaneous movementType.
     
  11. GohanCZ

    GohanCZ

    Joined:
    Apr 29, 2021
    Posts:
    32
    I believe they have fix in the 1.0.0-pre.4 ready.
     
    mattouBatou likes this.
  12. mattouBatou

    mattouBatou

    Joined:
    Sep 2, 2016
    Posts:
    20
    redcurry79 likes this.
  13. mattouBatou

    mattouBatou

    Joined:
    Sep 2, 2016
    Posts:
    20
    Where did you see information about what is coming with 1.0.0-pre.4?
     
  14. MarekLg

    MarekLg

    Joined:
    Jan 31, 2018
    Posts:
    26
    On the issue tracker
     
    mattouBatou likes this.
  15. GohanCZ

    GohanCZ

    Joined:
    Apr 29, 2021
    Posts:
    32
    Yep. Exactly there. Stumbled upon it when googling the issue myself.
     
  16. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    Confirmed fixed on 1.0.0-pre.4, thanks Unity team.

    One comment about the legacy attach setting, it might be nice to keep that instead of deprecating it. I'm using XRGrabInteractables on objects attached to hinge joints, and the legacy attach point option works a lot better for these type of objects for some reason. Haven't dug into why yet.