- Home /
Open GUI on Certain HTC VIVe Controller Angle/Turn
Hi guys,
I am Trying to make a Rec Room(htc vive game) Esque GUI but having trouble in opening the GUI on certain controller angle i have done some work and achieved a bit sketchy one which is opening at certain angle but other then that its opening when the Controller is straight in front of camera on 90 degree as i wanted it to open only when controller is at certain angle (as a guy looking at his watch)
Here is some code i have managed
void RayCastFromHead() // is just a name for Method i am raycasting from a dummy which contains left Grip button
{
if (Physics.Raycast(dummy.position, dummy.up, out hitInfo, 30))
{
transform.rotation.ToAngleAxis(out tempAngle, out tempAxis);
if (hitInfo.collider.name.Contains("Camera (eye)"))
{
if (dummy.gameObject.GetComponent<MeshRenderer>().enabled)
{
if ((transform.localEulerAngles.z > 270.0f && transform.localEulerAngles.z < 315.0f)&&
(transform.position.y > 0.9f && transform.position.y < 2f))
{
staticRotaion = transform.localRotation;
canvasOnHead.GetComponent<TweenScale>().PlayForward();
}
}
}
}
}
Here are some visual examples
I do not know that it is a right method to do this kind of task Kindly look into this matter Any help would be appreciable
Regards AR
What i would try:
add an empty gameobject to the hand so that its forward vector points directly at you when the hand is in the desired position
calculate the vector between the forward vector of that object and the forward vector of the camera/eye. If it's near 180 it's pointing at you.
Additionally, if you want to ensure that the hand is near the center of the display, you could add a sphere collider to the new object, make it about the size of a basket ball and use a raycast with with the forward vector of th e camera and check if it hits the sphere.
at Last someOne thanks... I have tried the Pretty much same logic u just described and its working but i am unable to detect the certain angle of the hand let say 180 deg this is where i cant work my way out i tried solutions but cant manage to detect the exact 180 rotation of hand (Camera and hands both are Child's of a main parent )