Delay Interactable VR Objects

Is there a simple way to delay Interactable Objects in Unity for a VR Environment? I just want objects to move with a delay when I grab and drag them around.

You could make an invisible child grabbable, that manages the parent with a delay and custom interacitons

You can also read out the trigger values and do everything manually via interactors

1 Like

Thank you for helping.
I made 2 seperate independent objects. First one has only a render component for visualisation, second one is an invisible XRGrabinteractable object.
This skript is on the visible rendered object:

using UnityEngine;
using System.Collections.Generic;

public class InteractablesDelay : MonoBehaviour
{
    public GameObject childObject; 
    public float delay = 0.2f; 

    private Queue<Vector3> positionHistory;
    private Queue<Quaternion> rotationHistory; 
    private Queue<float> timestamps;
    private float lastUpdateTime;

    void Start()
    {
        positionHistory = new Queue<Vector3>();
        rotationHistory = new Queue<Quaternion>();
        timestamps = new Queue<float>();
    }

    void Update()
    {
        if (Time.time - lastUpdateTime >= Time.fixedDeltaTime)
        {
            StoreHistory();
            lastUpdateTime = Time.time;
        }
        if (timestamps.Count > 0 && Time.time - timestamps.Peek() >= delay)
        {
            transform.position = positionHistory.Dequeue();
            transform.rotation = rotationHistory.Dequeue();
            timestamps.Dequeue();
        }
    }

    private void StoreHistory()
    {
        positionHistory.Enqueue(childObject.transform.position);
        rotationHistory.Enqueue(childObject.transform.rotation);
        timestamps.Enqueue(Time.time);
    }
}

Iā€™m open for improvement in the code.

1 Like