I’m having difficulty trying to alter the position of an object which I’m moving based on an HTC Vive controller. I want the object to follow the controller, which I’ve achieved by making the object’s position the same as the controller:
gameObject.transform.localPosition = new Vector3(viveController.transform.localPosition.x, viveController.transform.localPosition.y, viveController.transform.localPosition.z);
For the rotation I don’t want to completely copy the controller. I want the object (imagine a long rectangle) to be pointing upwards at 45 degrees at all time, which I believe is the X axis, while mirroring the Y and Z axis. I’m doing this by:
gameObject.transform.eulerAngles = new Vector3(45.0f, viveController.transform.localRotation.eulerAngles.y, viveController.transform.localRotation.eulerAngles.z);
Which works as I expect if I’m holding the controller flat or pointing slightly upwards to the ceiling, but as soon as I point the controller down towards the floor the object’s 45 degree angle pointing upwards flips (mirrors) to 45 degrees pointing down.
I believe this is because the three axes don’t appear to be individually changed, i.e. a change to the X axis in the 3D space will also change the Y and Z axes as well. What is happening and how can I achieve what I want? The object should always be pointing upwards regardless of the controllers orientation. Any advice on how to change a single axis without changing the other two would be appreciated!
I’ve tried a few things including trying localEulerAngles and some Quaternion stuff but I don’t really know what to search online to solve my issue. I’m trying to get the object to point at a global 45 degrees, and not relative to the controller. Thanks!