Forum Discussion
dre38w
4 years agoHonored Guest
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.
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!
1 Reply
- dre38wHonored Guest
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!
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago
- 6 months ago
- 4 years ago