Rotate an object in unity with vive controller around a fixed axis

Hey,

I’m quite new to Unity and currently trying to figure out how i can rotate an object around a fixed axis using only one of the vive controllers.

I think in theory I know what to do, but i’m not sure how to realise it or if it is even possible.

How it should work in Game:

  1. Start the “rotating-action” for the object by pressing and holding trigger button.
    2)Move the controller → the object rotates relative to controller movement until triggerbutton is released

So what I think i have to do is the following:

1)After a certain time the triggerbutton is pressed, get the vector between the point where I pressed down the triggerbutton and the point where the controller position is now.
2)Calculate the orthogonal/perpendicular to this Vector.
3)Put the orthogonal/perpendicular in the center of the object and rotate the object around it, for some degrees depending on the controllermovement, doesn’t matter at the moment.
4)Fix the rotation of the object to this rotation axis and continue rotating it, if triggerbutton is still pressed and the controller is moved.

I know it’s maybe hard to understand, so i made some pictures. (The shown controller-movement shall be an up-movement.)
In the first picture, you simply could rotate the object around its local x-axis.


But in the second picture you could’nt, because the coordinate system is “twisted”. And I’m wondering if my solution could work in this case?

So, my question is, if my imagination of how it could work is even possible? For example the orthogonal/perpendicular for the “controller-movement-vector” is not unique, is it?

Would be happy about any type of advise, I’ve trouble with this problem for a long time now …

Thank you in advance!

@rhaak17

I’m not sure I completely understand the main thrust of your question.

Are you trying to, for example, have the world space x rotation of the controller cause the object to rotate around it’s local x rotation?

If this is the case I think Transform.localEulerAngles will help.

You can also use hinge joints to constrain object rotation to a certain local axis.