【问题标题】:Unity3d HTC Vive Radial Menu - Weird GlitchingUnity3d HTC Vive 径向菜单 - 奇怪的故障
【发布时间】:2017-04-03 04:41:51
【问题描述】:

所以我编写了这个由左侧魔杖上的触控板控制的径向菜单。它通过我的手指在触控板上的位置确定要放大哪个按钮。

可以看到奇怪的动作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
            }
        }
    }

我很困在这里,任何帮助将不胜感激

【问题讨论】:

    标签: user-interface unity3d menu virtual-reality htc-vive


    【解决方案1】:

    "与 (touchPadAngle) 最接近的垂钓者差异"

    您不应该为径向刻度盘考虑多个轴吗?

    【讨论】:

    • 抱歉,我没听懂,还有没有遗漏的坐标轴?
    • 好吧,如果您考虑一下 - 当差异值太小时,它会在两个状态之间切换 - 视频似乎显示当两者水平时会发生这种情况 - 请随时离线联系我 -我还需要查看径向菜单代码/资产。
    猜你喜欢
    • 2020-08-03
    • 2012-06-07
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多