Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Custom VR glove controller

Discussion in 'VR' started by RobinNowlan, Aug 11, 2021.

  1. RobinNowlan

    RobinNowlan

    Joined:
    Jun 14, 2020
    Posts:
    2
    Hey all, I am making a custom VR glove and I am trying to figure out the best way to map values of the flex sensors on each finger in unity.

    There are two sensors per finger (one covering the middle and end joint and the other covering the knuckle). I am looking to have a clean and simple way to control the amount of bend (or flex) of each finger in the unity model.

    For example:
    Code (CSharp):
    1. indexFinger.middleJoint.anlge = 90;  //sets the middle joint to 90 degrees
    I know this code isnt corect, but I am looking for something similar.

    Is there a general "hand manager" or a way of controlling a rig that makes this process easy?
    Or even a package that can streamline the whole process?

    Greatly Appreciated
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    No, there isn't. You'll need to just set the rotations of each joint yourself. The code isn't that much different from what you posted:

    Code (csharp):
    1. indexFinger.middleJoint.localEulerAngles = (90, 0, 0); // sets the middle joint to 90 degrees
    But exactly which axis you rotate around will depend on how your hand model was made. There is no hard standard.

    Best,
    - Joe
     
    RobinNowlan likes this.
  3. RobinNowlan

    RobinNowlan

    Joined:
    Jun 14, 2020
    Posts:
    2
    Thank you, this helps a lot. One quick question, how would you structure it? These are a few ways I think I could do it.

    Code (CSharp):
    1. //New variable for each finger part
    2. public GameObject indexTip;
    3. public GameObject indexMid;
    4.  
    5. indexTip.localEulerAngles = (90, 0, 0);
    6.  
    7. //GameObject array for each finger
    8. public GameObject[] index;
    9. index = new GameObject[3];
    10. index[2] = indexTipObject.GameObject;
    11.  
    12. index[2].localEulerAngles = (90, 0, 0);
    13.  
    14. //Get GameObjects as children
    15. public GameObject indexFinger;
    16.  
    17. indexFinger.transform.getChild(0).localEulerAngles = (90, 0, 0);
    Thanks
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Personally I'd go with the first one — just declare a public property for each joint, and assign them in the inspector.