Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Giantbean · Oct 23, 2019 at 08:00 PM · vrhands

How can I code which hand is holding an object in SteamVR.

I have an object that can be grabbed using steamVR at two different locations. The SteamVR Intractable script paired with throwable script and and Steam VR_Skeleton_Poser script ( scripts found here https://github.com/ValveSoftware/steamvr_unity_plugin) allow the interaction to work however I would like to have different interactions based on which hand is holding the object.

I am trying: ///

If this is for the left or right hand public void SelectHand(SteamVR_Input_Sources handType) { MoveInteractSphereBasedOnHand(handType); }
         public void MoveInteractSphereBasedOnHand(SteamVR_Input_Sources inputSource)
         {
             if (inputSource == SteamVR_Input_Sources.LeftHand)
             {
                 hand.hoverSphereTransform = leftHoverTransform;
             }
 
             if (inputSource == SteamVR_Input_Sources.RightHand)
             {
                 hand.hoverSphereTransform = rightHoverTransform;
             }
         }

In a script using namespace Valve.VR as a starting point but the public void SelectHand() can not be called elsewhere or invoked so I don't even know how to test the code?

I just want to be able to have the held object interact differently based on where it is being held. Any ideas?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Strixie13 · Oct 24, 2019 at 03:38 AM

I usually just run a Vector3.Distance check between the raw hand tracking positions. Whichever hand has the shortest distance to the object is the one interacting with it. That could also work for the multiple points on the same object. Just see what point the controller is closest to, then run a different function depending on which one is closer.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Giantbean · Oct 24, 2019 at 09:15 PM 0
Share

This sounds very promising but I am unsure how to do what you say? Could you give me a code example?

avatar image Giantbean · Oct 24, 2019 at 09:19 PM 0
Share

By the way, I can grab the object in two locations already but only if the left hand grabs in one point and the right hand picks up in another so your idea could fix that but I also need to be able to move the hands hoverSphere transform because the item I am grabbing extends the reach and thus places further hand controls at the end of the object with each end activating different controls. With that in $$anonymous$$d do you think the Vector3.Distance method mentioned would be able to do this?

avatar image Strixie13 Giantbean · Oct 25, 2019 at 03:32 AM 0
Share

$$anonymous$$aybe post some of the code you have and I could get a better idea. Generally speaking what you are trying to do is create a grab system, tweaked to your game.


This is a function I wrote for one of my VR games that returns the nearest object. It takes a hand position and will find the nearest pickable game object (based on a layer mask). It might not actually run, just quickly re-typed some of it to show how it might work in an offline game (originally returns ID's and stuff since its in a networked game)

     public GameObject ClosestObject(Vector3 handPOS)
     {
         Collider[] nearbyObjects = Physics.OverlapSphere(handPOS, 2f);
 
         float shortestDist = $$anonymous$$athf.Infinity;
         gameObject closestObject = new GameObject(); 
 
         foreach (Collider col in nearbyObjects)
         {
             float dist = Vector3.Distance(col.transform.position, handPOS);
 
             if (dist < shortestDist)
             {
                 shortestDist = dist;
                 closestObject = col.gameObject; 
             }
         }
 
         return closestObject; 
     }

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

143 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

VR interactable soft bodies?? 0 Answers

Using Leap Motion Assets in Unity 4 0 Answers

Mirror Leap motion hands 1 Answer

how to change the mesh of the hands in oculus 1 Answer

Why does the object rotate around the hands with the "kinematic" parameter?,Why does the object move in the hands with the "kinematic" parameter? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges