- Home /
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!
Answer by solidearthvr · Aug 07, 2017 at 06:01 AM
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.
I think I already got a solution which works for me.
I wanted to rotate the object around it's local x axis when moving the vive controller in world's y direction and rotate it around its y axis when moving the vive controller in object's x direction.
But I didn't know what do to when the coordinate system of the object is not in it's 'initial state', for example when it was already rotated somehow. I didn't know around which axis I should rotate if the user moves the controller along the world's y axis.
$$anonymous$$y solution so far is to take the axis of the main camera(vr headset) to rotate around them. $$anonymous$$g. user moves the vive controller in world's y direction -> object rotates around camera's x-axis. Or user moves the vive controller in camera's x direction -> rotate object around world's y coordinate.
I hope it's clear know what my question was and how my solution looks like, I can imagine it's not easy to understand..
Either way, I got a solution that works for me, so I need no help anymore. Nevertheless, thank you for your answer solidearthvr ! :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612130655im_/https://answers.unity.com/themes/thub/images/avi.jpg)