ValveSoftware / steamvr_unity_plugin

SteamVR Unity Plugin - Documentation at: https://valvesoftware.github.io/steamvr_unity_plugin/
BSD 3-Clause "New" or "Revised" License
1.04k stars 257 forks source link

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

Open ischtz opened 3 years ago

ischtz commented 3 years ago

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:

StCost commented 3 years ago

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

ischtz commented 3 years ago

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

StCost commented 3 years ago

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