【问题标题】:Weird beeping on Vive Controller when firing haptics programmatically (Unity3D / SteamVR 2.0)以编程方式触发触觉时 Vive 控制器上发出奇怪的哔哔声 (Unity3D / SteamVR 2.0)
【发布时间】:2019-01-04 12:01:22
【问题描述】:

我在 Unity 上使用 SteamVR 2.0 以编程方式在我的 Vive Wand 上触发触觉时遇到了奇怪的行为。

为了让大家更好理解,我特地录了下来:https://www.youtube.com/watch?v=wq4OJUFghNI

基本上,我所做的只是一个简单的射击游戏,当你扣动扳机时,它每秒发射 3 发子弹并触发触觉。问题是如果您在触发触觉代码后立即释放触发器,听起来控制器触觉会卡住并且您会听到烦人的声音。重新触发触觉会停止该声音。

我已经尝试过用 Google 搜索,但似乎没有人经历过,因为我没有找到任何东西。我试图改变赋予函数的频率、持续时间或强度,但它没有改变任何东西(持续时间越短,没有这种行为的可能性就越大,但这不是解决办法)

ShootingBehaviour.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;

namespace RG
{
    namespace VR
    {
        public class ShootingBehaviour : MonoBehaviour
        {
            private bool _IsShooting = false;
            private bool _GrabPinchPressed = false;

            public GameObject BulletPrefab;
            public SteamVR_Action_Vibration HapticAction;
            public SteamVR_Action_Boolean GrabPinch;
            public SteamVR_Input_Sources InputSource;

            private void Start()
            {
                if (InputSource == SteamVR_Input_Sources.Any)
                {
                    if (CompareTag("LeftController"))
                        InputSource = SteamVR_Input_Sources.LeftHand;
                    else if (CompareTag("RightController"))
                        InputSource = SteamVR_Input_Sources.RightHand;
                    else
                        Debug.LogError("Tag on the controller GameObject is incorrect, check again if 'LeftController' or 'RightController' has been assigned.");
                }
            }

            private void Update()
            {
                if (_GrabPinchPressed)
                {
                    Debug.Log("Trigger is currently pressed");
                    if (!_IsShooting && GetComponent<InteractableBehaviour>().CurrentlyEquipped)
                    {
                        HapticAction.Execute(0, 0.1f, 80, 150, InputSource);
                        StartCoroutine(_Shoot());
                    }
                }
            }

            private void OnEnable()
            {
                if (GrabPinch != null)
                    GrabPinch.AddOnChangeListener(_OnTriggerPressedOrReleased, InputSource);
            }

            private void OnDisable()
            {
                if (GrabPinch != null)
                    GrabPinch.RemoveOnChangeListener(_OnTriggerPressedOrReleased, InputSource);
            }

            private void _OnTriggerPressedOrReleased(SteamVR_Action_In action_In)
            {
                if (GrabPinch.GetStateDown(InputSource))
                    _GrabPinchPressed = true;
                else if (GrabPinch.GetStateUp(InputSource))
                    _GrabPinchPressed = false;
            }

            private IEnumerator _Shoot()
            {
                _IsShooting = true;

                GameObject weapon = GetComponent<InteractableBehaviour>().CurrentlyEquipped;
                GameObject bullet = Instantiate(BulletPrefab, weapon.transform.Find("BulletStartPos"));

                bullet.transform.SetParent(null);
                bullet.GetComponent<Rigidbody>().AddForce(bullet.transform.forward * 300);

                yield return new WaitForSeconds(0.3f);

                _IsShooting = false;
            }
        }
    }
}

InteractableBehaviour 只是将武器存放在手中,展示它并没有任何帮助。

这里的HapticAction.Execute 正确触发了触觉,但由于某些原因,触觉似乎有些问题有时。有人知道为什么要这样做吗?

【问题讨论】:

  • _Shoot() 协程中有什么? /_IsShooting 设置在哪里?另请注意,调用GetComponent&lt;InteractableBehaviour&gt;() 效率很低,您应该这样做,例如在Awake 中并存储结果以备后用
  • 另外,我在SteamVr sdk 中没有找到HapticAction,所以如果这是您实现的......请您也添加这个吗?
  • 我找到了SteamVR_Action_Vibration,如果你指的是那个。那里说第三个参数"amplitude"&gt;How intense the haptic action should be (0 - 1) 你用150 调用它...?
  • 我编辑了我的问题并添加了整个ShootingBehaviour.cs 文件,只是“确保”没有任何遗漏,但我认为这对拍摄行为没有任何帮助 工作,不只是触觉。不会链接InteractableBehaviour.cs,原因与我提到的大致相同。 HapticAction.Execute 不是我的功能,它是 SteamVR 2.0 的一部分(编辑:哎呀,是的,因为它是 SteamVR_Action_Vibration
  • 我只是尝试更改 amplitude 参数,但它并没有改变任何东西(尝试了 1、0.2f 和 0)。 这有点奇怪,因为我看不出 1 和 0.2f 之间有什么区别。 0 不触发触觉,这是正常的

标签: c# unity3d htc-vive steamvr


【解决方案1】:

就像 Shoko84 所说,幅度参数没有区别。 事实上,在调用 HapticAction.Execute 时,所有参数似乎都没有任何区别

【讨论】:

    【解决方案2】:

    我相信参数有奇怪的限制。 持续时间:0 到 0.79 频率为 0 到 320 幅度为 0 到 .25

    如果您超过这些值中的任何一个,它们只是最大值。这就是为什么您没有看到幅度 0.2 和 1 之间有任何差异,它们几乎相同(强度差异 .o5)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      • 1970-01-01
      相关资源
      最近更新 更多