Search Unity

Help with Mirroring Oculus Controllers

Discussion in 'VR' started by Afroca, Jul 11, 2019.

  1. Afroca

    Afroca

    Joined:
    May 24, 2019
    Posts:
    1
    Currently I am trying to write a script that will mirror the movements of one controller onto the other for users who only have 1 functioning arm. Mirroring the y axis and z axis were easy since they move together and the rotation was easy to mirror. I am unable to mirror the x axis movement. I want it so that if the one hand moves out the other does the same, and they both move in together. Any ideas how I may be able to do this? I have attached my current script.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class VRMirror : MonoBehaviour
    {
    public bool mirrorLeft;
    public bool mirrorRight;
    public GameObject leftHand;
    public GameObject rightHand;
    void Start()
    {

    }
    void FixedUpdate()
    {
    Transform left = leftHand.GetComponent<Transform>();
    Transform right = rightHand.GetComponent<Transform>();
    if (mirrorLeft)
    {
    Vector3 leftPos = left.position;
    Quaternion leftRot = left.rotation;
    leftRot.y = -leftRot.y;
    right.position = leftPos;
    right.rotation = leftRot;
    }
    else if (mirrorRight)
    {
    Vector3 rightPos = right.position;
    Quaternion rightRot = right.rotation;

    rightRot.y = -rightRot.y;
    left.position = rightPos;
    left.rotation = rightRot;

    }
    }
    }
     

    Attached Files: