Rotate GameObject with controller of HTC vive
I'm using the HTC Vive and I want to rotate a valve's wheel with the controller position of HTC vive. I tried to calculate the angle between the different position of the controller and the center of the wheel. And after I make the rotation of the wheel. It's work but i have always a difference between the controller and the wheel position. The wheel don't rotate enough. The Wheel need to rotate only in Y axis.
Thank's for your help!
float angle; Vector3 axis;
Vector3 relativePos = (grabbingObject.transform.position - this.transform.position);
float calculateAngle = Vector3.Angle(oldRelativePos, relativePos);
Vector3 cross = Vector3.Cross(oldRelativePos, relativePos);
if (cross.y < 0) calculateAngle = -calculateAngle;
oldRelativePos = relativePos;
Quaternion rotation = new Quaternion();
if (calculateAngle != 0)
{
rotation.eulerAngles = new Vector3(0, calculateAngle, 0);
}
rotation.ToAngleAxis(out angle, out axis);
angle = (angle > 180 ? angle -= 360 : angle);
if (angle != 0)
{
Vector3 angularTarget = angle * axis;
rb.angularVelocity = Vector3.MoveTowards(rb.angularVelocity, angularTarget, 1000f);
}
Your answer
Follow this Question
Related Questions
Get axis perpendicular to x-axis and aligned to horizontal plane 1 Answer
Rotatearound and face the direction of movement 0 Answers
Clamp camera orbit rotation using RotateAround 2 Answers
Rotate an Object while moving forward using empty gameObject 0 Answers
Unwanted translation when rotating axisymettric object 0 Answers