Search Unity

[SteamVR 2.5] How can I programmatically attach an object to the hand?

Discussion in 'VR' started by carn1x, Feb 10, 2020.

  1. carn1x

    carn1x

    Joined:
    Jan 6, 2020
    Posts:
    2
    I would like to attach an object to the hand programmatically based on the hands entry into a given mesh. My current plan is to have the area mesh have an Interactable Hover Events component and call OnHandHoverBegin() to call a function to attach a separate object to the hand for the duration of the hands hover, and then to detach OnHandHoverEnd(). Thanks for any advice.
     
  2. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    144
    Did you ever find a solution to this?
     
  3. carn1x

    carn1x

    Joined:
    Jan 6, 2020
    Posts:
    2
    Actually I "cheated" and created a child game object (which I've called a "Cursor") of the Hand objects, and then when grabbing is detected I just force the OtherMesh to align as I need to the Cursor. Feels a bit hacky of course so I wouldn't say it is a solution, but for my needs right now it's good enough for prototyping.

    What I then found is that my Cursor is immediately representative of my hands really world position, where as the in-game hand model is lagged behind the Cursor / real-world position and has some sort of easing which I can't figure out, but as I'm still just prototyping and hand model accuracy is not a priority I've ignored this, but I hope to come back to it at some point.
     
  4. KieranCoughlanWG

    KieranCoughlanWG

    Joined:
    Apr 24, 2017
    Posts:
    1
    Was taking a peek in the Valve.VR.InteractionSystem.Hand class today and it does have an AttachObject() which supports a range of different attachment modes. There's also a few classes that reference this such as Throwable, ComplexThrowable, SpawnAndAttachAfterControllerIsTracking, SpawnAndAttachToHand, etc. which might be useful to try. I tried this myself, calling AttachObject() directly, and it seemed to work as expected.
     
  5. Theodor99

    Theodor99

    Joined:
    May 23, 2021
    Posts:
    1
    What GrabType did you use for the AttachObject() function?