cancel
Showing results for 
Search instead for 
Did you mean: 

Drag object on single local axis

dre38w
Level 2

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.

1 ACCEPTED SOLUTION

Accepted Solutions

dre38w
Level 2

Got it sorted. Here's the code in case anyone else has this issue:

 

  1. //find where objA is currently and where it was originally
  2. offsetFromStart = objA.position - objA.lastPos;
  3.             //project the direction onto the desired vector.
  4.             projectedVector = Vector3.Project(offsetFromStart, orientation.transform.forward);
  5.             //move along that vector
  6.             desiredPos = Vector3.Lerp(thisObjLastPos, thisObjLastPos + projectedVector, precision);
  7.             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!

View solution in original post

1 REPLY 1

dre38w
Level 2

Got it sorted. Here's the code in case anyone else has this issue:

 

  1. //find where objA is currently and where it was originally
  2. offsetFromStart = objA.position - objA.lastPos;
  3.             //project the direction onto the desired vector.
  4.             projectedVector = Vector3.Project(offsetFromStart, orientation.transform.forward);
  5.             //move along that vector
  6.             desiredPos = Vector3.Lerp(thisObjLastPos, thisObjLastPos + projectedVector, precision);
  7.             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!