Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Barty98's avatar
Barty98
Explorer
2 years ago
Solved

Bug report: Grabbable not positioning properly when force releasing then force selecting

Unity Version 2022.3.40f1

Meta XR Interaction SDK Version 69.0.2

I am currently using hand tracking with a Grabbable interactable. The interactable is a gun that I do not want the player to be able to drop so I use ForceSelect on spawn to bring the gun to the players hand. I want the player to be able to swap hands by grabbing the handle of the gun so I have a second mirrored Hand Grab Interactive with both max interactors set to 1. The main Grababble script is also set to max grab points 1.

I can grab the gun with my left hand and swap fine. It is when I then grab the gun back from my left hand when the Grabbable then gets set to world point zero, and my gun objec moves around on a pivot from world zero. The only way to fix this is to open the oculus menu then resume, the gun then teleports into the hand it should be in.

I reset the local position and rotation of my grabbables because they break when the application loses focus and start pivoting from world zero. This fix works for when I open the oculus menu and return but not for when grabbing back the gun from my left hand.

 

private void SwapHands(eHand newHand) {
        _secondHandleGrabbed = false;
        _interactorLeft.ForceRelease();
        _interactorRight.ForceRelease();


        if (newHand == eHand.Right) {
            _hand = eHand.Right;
            _interactorRight.ForceSelect(_handGrabbableRight, false);
        } else {
            _hand = eHand.Left;
            _interactorLeft.ForceSelect(_handGrabbableLeft, false);
        }

        _mainGrabbable.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
        _handGrabbableRight.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
        _handGrabbableLeft.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
    }

private void OnGunGrabbedLeft(PointerEvent evnt) {
        switch (evnt.Type) {
            case PointerEventType.Select:
                print("grabbed with left");
                SwapHands(eHand.Left);
                break;
        }
    }

    private void OnGunGrabbedRight(PointerEvent evnt) {
        switch (evnt.Type) {
            case PointerEventType.Select:
                print("grabbed with right");
                SwapHands(eHand.Right);
                break;
        }
    }

private void OnInputFocusAcquired() {
        _interactorLeft.ForceRelease();
        _interactorRight.ForceRelease();

        if (_hand == eHand.Right) {
            _interactorRight.ForceSelect(_handGrabbableRight, false);
        } else {
            _interactorLeft.ForceSelect(_handGrabbableLeft, false);
        }

        _mainGrabbable.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
        _handGrabbableRight.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
        _handGrabbableLeft.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
    }

 

 

 

Edit: Added images for extra context

Default held in right handGrabbed with left handGrabbed back into right hand, gun starts rotating from world zero

  • UPDATE: Fixed by setting my right Hand Grab Pose to be relative to the correct object. Still would be nice to not have to set the local position and rotation of grabbables back to zero whenever something is unselected.

1 Reply

Replies have been turned off for this discussion
  • UPDATE: Fixed by setting my right Hand Grab Pose to be relative to the correct object. Still would be nice to not have to set the local position and rotation of grabbables back to zero whenever something is unselected.