I am trying to drag an object and have it move on only one of its own axes. However, when the objects are rotated it only moves on the world axis. I have tried to use inverdirection, transform direction, point and rigid body constraints and nothing seems to work. Right now I log the initial position in a variable and then apply that position to the axes I want locked and set the desired axis to pull be its own axis value. Does anyone have this problem and a possible solution?
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!