Search Unity

Question (SteamVR) Motion controllers don't behave as should on model rig

Discussion in 'VR' started by RFlintstone, Sep 15, 2020.

  1. RFlintstone

    RFlintstone

    Joined:
    May 19, 2019
    Posts:
    2
    Hi all, I followed a 'How to make a body' tutorial for my VR game but it doesn't seem to work properly with SteamVR/The Knuckle controllers/Skeleton with inversed kinematics.

    What happens:
    1) The arms don't move at the right speed so you need to move more in order to get the arm moved just a little bit
    2) The hand does move left / right if you move the controller left/right but when you move the controller up the hand goes down (and the other way around, controller down hand goes up)

    I recorded a video so the text above is easier to understand (https://i.imgur.com/MrBKnv9.mp4)

    The script I use to make the hands/head rotate:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [System.Serializable]
    6. public class VRMap
    7. {
    8.     public Transform vrTarget;
    9.     public Transform rigTarget;
    10.     public Vector3 trackingPositionOffset;
    11.     public Vector3 trackingRotationOffset;
    12.  
    13.     public void Map()
    14.     {
    15.         rigTarget.position = vrTarget.TransformPoint(trackingPositionOffset);
    16.         rigTarget.rotation = vrTarget.rotation * Quaternion.Euler(trackingRotationOffset);
    17.     }
    18. }
    19.  
    20. public class VRRig : MonoBehaviour
    21. {
    22.     public VRMap head;
    23.     public VRMap leftHand;
    24.     public VRMap rightHand;
    25.  
    26.     public Transform headConstraint;
    27.     public Vector3 headBodyOffset;
    28.  
    29.     // Start is called before the first frame update
    30.     void Start()
    31.     {
    32.         headBodyOffset = transform.position - headConstraint.position;
    33.         //headBodyOffset = new Vector3(0, 0, 0);
    34.     }
    35.  
    36.     // Update is called once per frame
    37.     void Update()
    38.     {
    39.         transform.position = headConstraint.position + headBodyOffset;
    40.         transform.forward = Vector3.ProjectOnPlane(headConstraint.up, Vector3.up).normalized;
    41.  
    42.         head.Map();
    43.         leftHand.Map();
    44.         rightHand.Map();
    45.     }
    46. }
    47.  

    Is there any solution for this?