2016-11-19 1 views
1

그래서 왼쪽 지팡이의 트랙 패드로 제어되는 방사형 메뉴를 작성했습니다. 트랙 패드에서 내 손가락 위치로 확대 할 버튼을 결정합니다.Unity3d HTC Vive 방사형 메뉴 - 이상한 글리치 화

이상한 움직임은 here으로 볼 수 있습니다.

여기 나는이 문제와 관련된 코드 인 왼쪽 지팡이를 공격했습니다.

SteamVR_TrackedObject obj; //The wand 
public GameObject buttonHolder; //All the buttons will be children of this object 
public bool buttonEnabled; 

void Awake() { 
    obj = GetComponent<SteamVR_TrackedObject>(); //this will be left hand controller 
} 


void Update() { 
    var device = SteamVR_Controller.Input((int)obj.index); 

    //if touchpad touched 
    if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) 
    { 
     if (buttonEnabled) //if radial menu is open 
     { 
      //touchPadAngle: Get the angle between touch coord and X-axis 
      Vector2 touchedCoord = device.GetAxis(EVRButtonId.k_EButton_Axis0); //what is this line each variable 
      float touchPadAngle = VectorAngle(new Vector2(1, 0), touchedCoord); //(1, 0) is X-axis 


      // ------------------- Find closest button ------------------------ 
      //Description: The process will be done by calculating the angle between button_Vector2 and X-axis (button_V2_to_10) 
      //   And then find the button with the closest angler difference with (touchPadAngle). 
      float minAngle = float.PositiveInfinity; 
      Transform minButton = transform; //Temperatry assign wand tranform to it. 
      float pad_N_button_Angle = 0.0f; //Angle between touchPadAngle and buttonAngle. 

      Vector2 button_V2_to_10; 
      float button_Angle; 
      foreach (Transform bt in buttonHolder.transform) 
      { 
       button_V2_to_10 = new Vector2(transform.position.x, transform.position.z) - new Vector2(bt.position.x, bt.position.z); 
       button_Angle = VectorAngle(new Vector2(1, 0), button_V2_to_10); 

       pad_N_button_Angle = Mathf.Abs(button_Angle - touchPadAngle); 
       //Both buttonAngle and touchPadAngle range from -180 to 180, avoid Abs(170 - (-170)) = 340 
       pad_N_button_Angle = (pad_N_button_Angle > 180) ? Mathf.Abs(pad_N_button_Angle - 360) : pad_N_button_Angle; 

       if (pad_N_button_Angle < minAngle) 
       { 
        minButton = bt; 
        minAngle = pad_N_button_Angle; 
       } 
      } 

      //Magnify the closest button 
      foreach (Transform bt in buttonHolder.transform) 
      { 
       GameObject btGO = bt.gameObject; 
       if (!btGO.GetComponentInChildren<ButtomHandler>().onHover && bt == minButton) { 
        //Magnify 
       } 
       else if (bt != minButton && btGO.GetComponentInChildren<ButtomHandler>().onHover) 
       { 
        //minify 
       } 
      } 
     } 
     else { 
      activateButtonMenu(); 
     } 
    } 


    //dis-hover all button if leave touch pad 
    if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { 
     //Hover the closest button 
     foreach (Transform bt in buttonHolder.transform) 
     { 
      GameObject btGO = bt.gameObject; 
      if (btGO.GetComponentInChildren<ButtomHandler>().onHover) 
      { 
       //minify 
      } 
     } 
    } 

내가 여기 아주 stucked 해요, 어떤 도움이 정말

당신이 반경 방향에 대해 둘 이상의 축을 고려하지합니다

답변

1

"(touchPadAngle)와 가장 가까운 낚시꾼 차이를"감사하겠습니다 다이얼?

+0

미안하지만, 놓친 축이 더 많습니까? – libra

+0

만약 당신이 그것에 대해 생각한다면 잘 - 차이 값이 너무 작 으면 두 주 사이를 토글하는 것입니다 - 두 비디오가 수평 일 때 비디오가 나타나는 것처럼 보입니다 - 오프라인에서 저에게 연락하게 자유롭게 - 저는 방사형을 볼 필요가 있습니다 메뉴 코드/자산도 포함됩니다. – dljava

관련 문제