XRGrabInteractable attach positioning fix (when track rotation is off)

Yet another positioning bug. :frowning:
Using pre5 with default attach point compatibility mode.

If the interactable has an attach transform set, and track rotation = off, grabbing this item will result in weird positioning. When rotating the interactor, the interactable rotates around it, meaning the attach point is wrongly calculated to a fixed local position on the interactor.

Original code:

Vector3 GetWorldAttachPosition(XRBaseInteractor interactor)
{
    return interactor.attachTransform.position + interactor.attachTransform.rotation * m_InteractorLocalPosition;
}

The code for m_InteractorLocalPosition says:

// Point we are attaching to on this Interactable (in Interactor's attach coordinate space)
Vector3 m_InteractorLocalPosition;

so I woud have changed the method to do this:

return interactor.attachTransform.TransformPoint(m_InteractorLocalPosition);

But that doesn’t work, so something is obviously wrong with m_InteractorLocalPosition. I just brute-forced what it should be from original values and it works, but don’t play supernice with the rest of the system:

Vector3 GetWorldAttachPosition(XRBaseInteractor interactor) {
    if (m_AttachTransform != null) {
        var deltaPositionInWorldSpace = attachTransform.TransformDirection(attachTransform.localPosition);
        var deltaPositionInInteractorLocalSpace = interactor.attachTransform.InverseTransformDirection(-deltaPositionInWorldSpace);
        return interactor.attachTransform.TransformPoint(deltaPositionInInteractorLocalSpace);
    }
    else {
        return interactor.attachTransform.position;
    }
}

I hope they fix the real problem when solving this. I’m not spending more time on this, because I have a feeling it’s a rabbit hole.

Ooh, please raise a bug on this!

@Matt_D_work : Sure, as soon as you have a sandbox example scene I can use when sending the bug report. Preferably as a Sample in the package.

PS, I forgot to mention this is with “force grab” off on the ray interactor.

Just kidding not kidding. You really should have had such a sample scene at least a year ago. Creating bug reports without sample projects are a waste of time.

However I’m having second thoughts if this is a bug or a misconception in how “track rotation” should work. I will think it over this weekend.

OK, I have now spent a few more hours investigating this :(.

The problem is when the collider position/size does not match the transform. We now get very weird behaviour in the attachposition (even if using default=none). This time I created a test project to show this, and I’ll submit a bug report.

But honestly, attaching interactables to interactors should be a core feature well tested and solved long ago. If you can’t do unit tests, at least create a test scene, where you go through all functions and edge cases before releasing the update. I’m starting to regret not creating my own framework… :confused: