Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Referenced Hand Positioning in VR

Discussion in 'AR/VR (XR) Discussion' started by mharris45, Jul 16, 2020.

  1. mharris45

    mharris45

    Joined:
    Aug 1, 2013
    Posts:
    1
    I'm hoping someone can provide some guidance here. I have a top down viewpoint of a character that has movement and camera following working quite nicely. I'm attempting to have the character's hands rotate around the player, mimicking my real hands in VR as they move along the XZ axis, but always restricted to a Y position of 1. Meaning, the hand markers cannot go up or down.

    I have the following code, but it simply does not work. i'm attempting to use the head position (VRCamera) and the VRHand positions to get the angle to translate down to my character. Even a slight movement causes the hands to rotate 2x times around the character very fast.

    Code (CSharp):
    1.     // Update is called once per frame
    2.     void Update()
    3.     {
    4.         // LineRenderer lr = GetComponent<LineRenderer>();
    5.         // lr.SetPosition(0, transform.position);
    6.         // lr.SetPosition(1, transform.forward);
    7.         Vector3 cp = VRCamera.transform.localPosition;
    8.         Vector3 hp = VRHand.transform.localPosition;
    9.         angle = Vector3.Angle(new Vector3(cp.x, 1, cp.z), new Vector3(hp.x, 1, hp.z))*.1f;
    10.         float z = Mathf.Cos(angle) * handRadius;
    11.         float x = Mathf.Sin(angle) * handRadius;
    12.         transform.localPosition = new Vector3(x, 2f, z);
    13.         // Debug.Log(gameObject.name+": "+transform.position);
    14.     }
    15.  
    I know this must be pretty basic and I'm missing something very simple....