Search Unity

VIVE Question | Stick an oject to another in VR? Or a holster technique?

Discussion in 'AR/VR (XR) Discussion' started by davidhughes3d, Sep 22, 2016.

  1. davidhughes3d

    davidhughes3d

    Joined:
    Nov 30, 2012
    Posts:
    29
    Hi,

    Newb question here. Can anyone tell me how I would "stick" an object to another. Or create a holster?

    Example: I would like to have my VR player be able to holster or "stick" their weapon/ammo/health-pack to their in-game character. And be able to take it off/put it back onto their character.

    Creating a place for the object to live/rest is simple enough with a Null object on the Camera Rig. Where I am stumped is how to make, say, a gun, stick to the players hip and or holster and be able to be retrieved at will.

    I am using VR Weapon Interactor to handle the guns, VRTK (Tool Kit) and a few other assets for AI etc. They all work well together and everything jives. I just cant for the life of me figure out where I can find a script or how to code one that would allow the player to stick an object to another and retrieve it at will.

    I have been through every single VRTK script and i can't see anything that relates to what i am looking for. I even experimented with using the container/drawer scripts to no avail.

    I am looking to implement a setup similar to the game "RAW DATA" . It has the kind of what I am looking to do.

    Any advice or pointers would be greatly appreciated. I might be missing something obvious, so bare with me here.

    Thank you in advance.
     
  2. NickAtUnity

    NickAtUnity

    Unity Technologies

    Joined:
    Sep 13, 2016
    Posts:
    84
    My first thought would be that you can simply parent the object to the camera (or your player, depending on how you setup your game objects) when you want to holster it. So when the player puts it in a specific point in space and presses some button, you just make that object no longer track their hand and instead be parented to the camera/player. Then it will stay in the same relative position so they can retrieve it.

    At least I think that gets at what you're talking about. Let me know if I totally missed it. :)
     
  3. davidhughes3d

    davidhughes3d

    Joined:
    Nov 30, 2012
    Posts:
    29
    Hi Nick,

    Thanks for your reply. That is sort of what I am trying to do. Where the ambiguity lies is in how to make said object actually stay in that position or be able to be removed from it via code.

    Also supposing the gun for example was parented in the hierarchy, this may work initially but if there are various weapons im not sure that would work. I may well be mistaken.

    The VRTK scrips have many different options pertaining to interacting with objects ie. pick up drop etc.. As well the VR Weapon Interactor has built into it the ability to pick up the gun object. But no inherit way to stick an object to another.

    What i am looking for is some sort of script/method that would say, "Once this collider on this object (movable) touches the collider on this object (static object or "holster"), stay in this position here. Otherwise if moved away by the player/controller, release it.
     
  4. NickAtUnity

    NickAtUnity

    Unity Technologies

    Joined:
    Sep 13, 2016
    Posts:
    84
    If you use standard transform parenting, it will stay in the same position relative to the parent, regardless of how the parent moves or rotates. You can use SetParent to easily set the parent for an object. When you want to unholster the item, simply set the parent to null and then begin tracking the hand as you were.
     
  5. davidhughes3d

    davidhughes3d

    Joined:
    Nov 30, 2012
    Posts:
    29
    Okay, I got it working now. Thanks for your advice.
     
    NickAtUnity likes this.