XR Interaction Toolkit Two Hand Grab and XRSocketInteractor Erros
I am working on a VR app, this app uses the XR interaction toolkit, i am trying to implement the Two hand grab on a object, this works fine but whenever i put the object on the socket, it has a big offset with the attach transform, this only happens when using both the Two hand Grab and the XRSocketInteractor, using the normal XRGrabInteractable works fine with the same sockets. The code i am using is a slight modification of the code on this video https://www.youtube.com/watch?v=Ie0-oKN3Lq0&t, my modifications are not the issue as the error happens even when using the original code.
Answer by Daar375 · Mar 29 at 09:57 PM
The code of the TwoHandGrabInteractable, the modifications i made are for another bug in the interaction with the socket, even without them the same offset is happening
public class TwoHandGrabInteractable : XRGrabInteractable
{
[SerializeField]
private List<XRSimpleInteractable> secondHandGrabPoints = new List<XRSimpleInteractable>();
public XRBaseInteractor secondInteractor;
// Start is called before the first frame update
void Start()
{
foreach (var item in secondHandGrabPoints)
{
item.onSelectEnter.AddListener(OnSecondHandGrab);
item.onSelectExit.AddListener(OnSecondHandRelease);
}
}
public override void ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase updatePhase)
{
if(secondInteractor && selectingInteractor)
{
selectingInteractor.attachTransform.rotation = Quaternion.LookRotation(secondInteractor.attachTransform.position - selectingInteractor.attachTransform.position, selectingInteractor.transform.up);
}
base.ProcessInteractable(updatePhase);
}
public void OnSecondHandGrab(XRBaseInteractor interactor)
{
if (selectingInteractor)
if (selectingInteractor.gameObject.tag != "socket")
{
secondInteractor = interactor;
}
}
public void OnSecondHandRelease(XRBaseInteractor interactor)
{
secondInteractor = null;
}
protected override void OnSelectEnter(XRBaseInteractor interactor)
{
base.OnSelectEnter(interactor);
}
protected override void OnSelectExit(XRBaseInteractor interactor)
{
base.OnSelectExit(interactor);
secondInteractor = null;
}
public override bool IsSelectableBy(XRBaseInteractor interactor)
{
bool isAlreadygrab = (selectingInteractor && !interactor.Equals(selectingInteractor)) ;
if (selectingInteractor)
{
if (selectingInteractor.gameObject.tag == "socket" && interactor.gameObject.tag == "Hand")
{
selectingInteractor.gameObject.GetComponent<XRSocketInteractor>().socketActive = false;
secondInteractor = null;
isAlreadygrab = false;
}
}
return base.IsSelectableBy(interactor) && !isAlreadygrab;
}
}
Your answer
