Open the GUI on a specific HTC VIVE Angle / Turn controller

I am trying to create a graphical interface for HTC VIVE, but I can’t open it at a certain level of the controller .

I did some work and got a little sketchy because my object is a child, because of which it is difficult for me to track its rotation or position, since I wanted it to open only when the controller is at a certain angle (like a guy looking on the watch)

Here are some visual examples:

This is my controller rotation without a GUI: Normal GUI is closed

When I rotate the controller, the GUI should display something like this: at an angle (as a guy looks at his watch) GUI Open

Here is some code that I controlled

   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();

                        }
                }
            }
        }

    }

, ? .

,

This is my hierarchy.

, , , - - enter image description here

+4
1

.

, . . ( ) , .

, World Space.

():

enter image description here

canvas ( - pos.z, z. , )

enter image description here

, ():

enter image description here

script

public class LookAtWatchController : MonoBehaviour
{
    public GameObject menuGUI;
    public GameObject hand;
    void Update(){
          if(transform.eulerAngles.x > 10)
          {
                menuGUI.transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, 0);
                menuGUI.SetActive(true);
                menuGUI.transform.position = hand.transform.position;
          }
          else{
                menuGUI.SetActive(false);
          }
     }
}

gui menuGUI

hand

menuGUI:

menuGUI.transform.eulerAngles = new Vector3(transform.eulerAngles.x, hand.transform.eulerAngles.y, hand.transform.eulerAngles.z);

, menuGUI.transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, 0); .

, rotation.nger.html.x , .

enter image description here

enter image description here

+1

Source: https://habr.com/ru/post/1666073/


All Articles