- Home /
Leap Motion, grab and rotate object
Hello community! I've been experimenting on a Desktop app using Leap Motion in Unity where, I want to grab a cylinder with the Leap Hands and then rotate it around its center axis. I only want it to be able to rotate around this specific axis and not the other two, like a volume knob, and this rotation will affect the movement of another object in the scene. I used freeze position property on of the rigidbody for all axes so that it can't move around when the leap hands are moving. So I tried to do the same for the rotation too, but it doesn't seem to work. Could you please give me any ideas on how to do that???
Thank you very much in advance.
Answer by killer-rabbit · Sep 06, 2018 at 02:22 PM
Hello again. I figured out a solution for this problem, I added these few lines of code to my interactive object:
Quaternion objRot = _intObj.rigidbody.rotation; //_intObj is the interactive object
Vector3 inEuler = objRot.eulerAngles;
if (inEuler.y != 0F || inEuler.z != 0.0F) {
inEuler.y = 0F;
inEuler.z = 0F;
objRot = Quaternion.Euler(inEuler);
_intObj.rigidbody.rotation = objRot;
}
It seems to be working, so my object only rotates around axis x when I grab it. The only problem is that it is flckering quite a lot now that its rotation is constrained and I don't know how to change/fix that. Any ideas would be welcome.
Thanks
Your answer
Follow this Question
Related Questions
Rotating an object based on the side the player is looking at 2 Answers
2D Rotate object so y axis faces other object 1 Answer
Rotate object 1 Answer
Y forward on rotation not X 1 Answer