Search Unity

Snapping an object to a specific place in VR.

Discussion in 'AR/VR (XR) Discussion' started by MSachs, Dec 6, 2019.

  1. MSachs

    MSachs

    Joined:
    Nov 22, 2017
    Posts:
    122
    Hi,

    I just started working with the HTC Vive and need some advice.
    My goal is to put specific objects into a specific place, indicating that it is the correct location and then snapping in place after letting go of the object. Similar to this situation in "Wrench"


    So far I used OnTriggerEnter and OnTriggerExit to change the emission colour of the material to indicate the correct or wrong position which works fine.

    But when I try to snap the object to a specific place it seems that the grab input by the controller overrides the snap function. So it snaps to the place for 1 frame but immediately follows my hand again.

    Long story short: How can I register when I let go of the object to call the snapping function from there.

    *Edit: I am using the SteamVR plugin if that is important.

    Thanks in advance :)
     
  2. FlamingVorpalCow

    FlamingVorpalCow

    Joined:
    Oct 29, 2014
    Posts:
    6
    If you have some kind of code that allows the object to be grabbed you could disable it, so it can't be grabbed anymore.
     
  3. MSachs

    MSachs

    Joined:
    Nov 22, 2017
    Posts:
    122
    Right now I am only using the native SteamVR components.
    So I have the "Interactable" and "Throwable" script attached to the object. Disabling the "Interactable" script doesn't seem to do anything and the "Throwable" script doesn't seem to allow to be deactivated...
     
  4. TechnOllieG

    TechnOllieG

    Joined:
    Mar 24, 2020
    Posts:
    1
    I'm guessing you've figured this out already? But I'll post this anyway to help anyone else with the same issue.

    I was having the same issue with not being able to disable the interactable or throwable scripts. What I did instead was that I made a copy of the object, removed the scripts on that object and then simply disabled the object with the scripts on it and enabled the object without the scripts.

    To answer your main question, if you're using the namespace Valve.VR.InteractionSystem and also have the Interactable script on the object; there are methods called OnHandHoverBegin, OnHandHoverEnd, OnAttachedToHand, and OnDetachedFromHand. Use these to trigger code when you, in this case, let go of the object (OnDetachedFromHand).
     
  5. hassancortex

    hassancortex

    Joined:
    Oct 27, 2019
    Posts:
    7
    I have this same issue and I have not been able to resolve it. I am using SteamVR 2x and it keeps returning several errors if I attempt to use VRTK. I know VRTK has the capability. Does anyone know the alternatives available if using only SteamVR 2x