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
1
Question by SteenPetersen · Jan 28, 2019 at 10:59 PM · vrikhand

Picking up Items in VR and keeping hand in position.

Hey all,

Been dealing with this problem for 2 days now so I though Id give it a shot here:

This is as far as I have gotten, Its working quite well. But since I am connecting the sword directly to the wrist bone of the rig to attain this effect, it is pushing the wrist out of the way and giving me a weird hand animation. However its locked position is exactly what I want, something alla blade and sorcery.


alt text


I am now however beginning to wonder if my approach is flawed from the outset and am considering doing it all over if anyone has a better approach. I have final ik, puppetmaster to help with the solution. But I cant really seem to get any help anywhere. If anyone wishes to work on thjis with me Id be most grateful and put out a tutorial to make it easier for others in the future.


On the sword is a copy of the hand Object that has been placed in that fingers closed pose and given a handpose script:

 public class HandPose : MonoBehaviour
 {
     public Transform[] transforms { get; private set; }
 
     void Awake()
     {
         transforms = (Transform[])GetComponentsInChildren<Transform>();
     }
 }


On the actual hand in the rig hierarchy the hand is given the handTarget script:

 public class HandTarget : MonoBehaviour
 {
     [Range(0f, 1f)] public float weight = 1f;
     public HandPose currentPose;
     public Transform handBone;
 
     public Transform[] transforms = new Transform[0];
     private Vector3 position;
     private Vector3 lastPosition;
     private Quaternion rotation = Quaternion.identity;
     private Quaternion lastRotation = Quaternion.identity;
     private Quaternion[] localRotations = new Quaternion[0];
     private Quaternion[] lastLocalRotations = new Quaternion[0];
 
     private float lerpWeight;
     private float lerpV;
     private HandPose lastPose;
 
     void Start()
     {
         transforms = (Transform[])handBone.GetComponentsInChildren<Transform>();
         localRotations = new Quaternion[transforms.Length];
         lastLocalRotations = new Quaternion[transforms.Length];
 
         position = transform.position;
         rotation = transform.rotation;
         lastPosition = position;
         lastRotation = rotation;
 
         for (int i = 2; i < transforms.Length; i++)
         {
             localRotations[i] = transforms[i].localRotation;
             lastLocalRotations[i] = transforms[i].localRotation;
         }
     }
 
     void LateUpdate()
     {
             if (weight <= 0f) return;
             if (currentPose == null) return;
 
             // Changing the pose
             if (currentPose != lastPose)
             {
                 position = lastPosition;
                 rotation = lastRotation;
 
                 for (int i = 1; i < transforms.Length; i++)
                 {
                     localRotations[i] = lastLocalRotations[i];
                 }
 
                 lerpWeight = 0f;
                 lastPose = currentPose;
             }
 
             lerpWeight = Mathf.SmoothDamp(lerpWeight, 1f, ref lerpV, 0.1f);
 
             Vector3 p = Vector3.Lerp(position, currentPose.transform.position, lerpWeight);
             transform.position = weight >= 1f ? p : Vector3.Lerp(transform.position, p, weight);
             lastPosition = transform.position;
 
             Quaternion r = Quaternion.Lerp(rotation, currentPose.transform.rotation, lerpWeight);
             transform.rotation = weight >= 1f ? r : Quaternion.Lerp(transform.rotation, r, weight);
             lastRotation = transform.rotation;
 
             for (int i = 1; i < transforms.Length; i++)
             {
                 Quaternion localR = Quaternion.Lerp(localRotations[i], currentPose.transforms[i].localRotation, lerpWeight);
                 transforms[i].localRotation = weight >= 1f ? localR : Quaternion.Lerp(transforms[i].localRotation, localR, weight);
                 lastLocalRotations[i] = transforms[i].localRotation;
             }
 
     }


And when picking up the sword a custom event is fired:

     /// The pose for holding this Item
     [SerializeField] Transform _myRightHandPose;
     /// the attachment position of the item to the wrist
     [SerializeField] Transform attachmentPos;
     /// the IK system of the player
     private VRIK ik;
     /// the hand we wish to modify
     private HandTarget rightHandTarget;
   
  public void MyOnGrabEvent()
     {
         if (rightHandTarget.weight >= 0.1f)
         {
             rightHandTarget.weight = 0.03f;
         }
 
         rightHandTarget.currentPose = _myRightHandPose.GetComponent<HandPose>();
 
         ik.solver.rightArm.target = attachmentPos;
 
     }


Any help is appreciated.

Comment
Add comment · Show 2
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 Magso · Jan 29, 2019 at 01:01 AM 0
Share

Have you tried putting the rig and the sword on different collision layers?

avatar image SteenPetersen Magso · Jan 29, 2019 at 07:38 AM 0
Share

Thank you for the input, but the issue here is not pertaining to collisions. what you see in the gif is that the sword becomes part of the rig and the hand has no guidance and so this happens. Im not quite sure how to control the hand correctly from here.

0 Replies

· Add your reply
  • Sort: 

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

129 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

Related Questions

Steam VR hands hit an invisible wall 0 Answers

SteamVR 2.6.1 hand lags when using joystick movement 1 Answer

Setting up FinalIK VRIK with animated movement 1 Answer

Vive Trackers model rotation shifts when running the scene in Unity 1 Answer

Problem with audio cue playing in VR then the audio staying headlocked with ear it played from, when it should stay at the audio object location. 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