steamvr_unity_plugin icon indicating copy to clipboard operation
steamvr_unity_plugin copied to clipboard

SteamVR_Action_Vibration: *secondsFromNow* seems to have no effect, haptics always start immediately

Open ischtz opened this issue 3 years ago • 3 comments

Hi all,

I am trying to generate controller haptics at predefined time offsets using the secondsFromNow argument of SteamVR_Action_Vibration.Execute(). However, haptics are always triggered immediately regardless of the value passed for this argument (and all code examples I could find online use 0f for this value anyway). The remaining arguments work as expected.

Am I doing something wrong, is this not the intended use of this parameter? I'd appreciate any pointers. Thanks!

Minimal example:

// AudioSource
beep.PlayOneShot(start_beep, 1f);

// SteamVR_Action_Vibration controllerHaptics is assigned to \actions\default\out\haptics in Inspector
controllerHaptics.Execute(latency, duration, frequency, intensity, SteamVR_Input_Sources.RightHand);

Expected result: Haptics triggers ~latency seconds after the sound plays.

Actual result: Haptics and sound always occur together regardless of latency, tested values in range 0.01f - 10f.

Tested versions:

  • SteamVR Unity plugin v2.7.3 (sdk 1.14.15)
  • SteamVR 1.18.7 with Unity 2019.4.24f1
  • SteamVR 1.19.5 with Unity 2019.4.16f1 and 2021.1.7f1,
  • Tried both legacy VR and XR plugin mode for 2019.4.16f1
  • Tested with Vive (classic and Pro) and Index controllers

ischtz avatar Aug 03 '21 20:08 ischtz

Same issue. Seems like this argument doesnt do anything. Had to make a workaround with async/await

StCost avatar Sep 14 '21 14:09 StCost

Looks like this is related to https://github.com/ValveSoftware/openvr/issues/1101.

ischtz avatar Sep 21 '21 13:09 ischtz

Considering, issue still opened after 2 years, it will never be fixed. So we must make workaround with async/await or coroutines

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

[System.Serializable]
public class Vibrator
{
    public SteamVR_Action_Vibration action;
    public SteamVR_Input_Sources handType;
    [Space]
    public float secondFromNowOn = 0f;
    public float durationSeconds = 0f;
    [Range(0, 320)]
    public float frequency = 0f;
    [Range(0, 1)]
    public float amplitude = 0f;

    public async void Execute()
    {
        if (amplitude > 0 && frequency > 0 && durationSeconds > 0)
        {
            if (secondFromNowOn > 0)
                await System.Threading.Tasks.Task.Delay((int)(secondFromNowOn * 1000));
            action.Execute(
                secondFromNowOn,
                durationSeconds,
                frequency,
                amplitude * SettingsManager.Instance.data.vibrationPower,
                handType
            );
        }
    }
}

StCost avatar Sep 22 '21 08:09 StCost