So I understand that XR Interaction Toolkit is coming up with a solution to this. But before that happens, I need to fix this problem for my project.
When I pick up an object using a ray interactor (or direct interactor), the rotation of the object always resets to match the “hand” or controller. I need the object to keep its rotation. I’m trying to add a script to do this but I can’t seem to get it right. I tried to get the rotation this way:
void Start()
{
interactor = grabee.transform.GetComponent<XRGrabInteractable>();
}
void Update()
{
interactor.selectEntered.AddListener(GetRotation);
}
void FixedUpdate()
{
if(interactor.isSelected)
RotateWith();
if(interactor.isSelected)
MoveWith();
}
public void GetRotation(SelectEnterEventArgs args)
{
flag = true;
originalRotation = grabee.transform.localRotation;
}
public void MoveWith()
{
grabee.transform.position = grabber.transform.position;
}
public void RotateWith()
{
if(flag)
{
grabee.transform.localRotation = grabber.transform.localRotation * originalRotation;
flag = false;
}
else
{
grabee.transform.localRotation = grabber.transform.localRotation;
}
}
But I think I need to get the rotation right before selectEntered. But I don’t know how or if that’s really the way. Any help would be much appreciated.