Hi,
I want to create a script and attach it to the left controler that waits for input on the primary2DAxis and rotate the camera by a certain degree when, for example, the x value surpasses 0.7 or someting.
My question is: how do I properly manipulate the viewport/camera? So far I wrote a script and attached it to the left hand node in unity that gets the headmounted and left controller input devices, gets the primary2DAxisValue in the update function. How do I manipulate the viewport/headmounted display rotation?
Thanks in advance for any help. Please also feel free to correct my approach if it’s bad practice.
6867371–801227–LookAround.cs (1.08 KB)
It sounds like you may be able to just use the Snap Turn Provider unless you’re trying to script other functionality.
In a typical setup, the Camera GameObject will also have a Tracked Pose Driver component which reads the position and rotation of the HMD and applies it to the Transform every frame. This means that if you try to update the Transform position of the Camera in your LookAround script, it will be overridden by the Tracked Pose Driver when it executes to make the Transform match the HMD.
To cause the camera to be effectively rotated, you would instead want to rotate a parent object. In XR Interaction Toolkit, this is done by rotating the XR Rig object, which is a parent of the Camera. For a code example, you can look at SnapTurnProviderBase
which uses the XRRig.RotateAroundCameraUsingRigUp
method. This causes the XR Rig to rotate about the Camera’s position by a given angle. It additionally checks that the LocomotionSystem allows the operation, which may be something you would want to also check.