- Home /
Oculus Quest drag object on single local axis
Hello.
I am trying to drag an object on one of its own axes using the Oculus GrabBegin function. This works fine when the rotation of the object is zeroed. When the object is rotated the object is dragged on the world axis rather than local.
I log the initial position and rotation when I grab the object and then apply those values to the axes I want locked every frame. I’ve tried using transformdirection, inversetransformdirection, and variations of the space conversion functions, tried normalizing the vector and nothing works.
Is there an Oculus feature built in for this or is there another way to be able to drag this object along its own axis?
Thank you.
Answer by dre38w · May 02 at 01:24 PM
Got it sorted. Here's the code in case anyone else has this issue:
//find where objA is currently and where it was originally
offsetFromStart = objA.position - objA.lastPos;
//project the direction onto the desired vector.
projectedVector = Vector3.Project(offsetFromStart, orientation.transform.forward);
//move along that vector
desiredPos = Vector3.Lerp(thisObjLastPos, thisObjLastPos + projectedVector, precision);
transform.position = desiredPos;
ObjA being the object I am dragging. Logging where it is when I initially grab it "objA.lastPos". thisObjLastPos being where the object that I want to actually move was before I grabbed objA. Hope this helps if anyone has this issue!