Home > Net >  How to track in which direction user is looking in unity oculus VR
How to track in which direction user is looking in unity oculus VR

Time:12-09

I am new to unity and testing VR development with Oculus quest 2 using XR Plugin management. I want to make a simple program where if user looks at left or right side I want to console it. It would be great if anyone can guide me or refer me to some good tutorial or docs.

CodePudding user response:

Grab a reference to the camera, it will be always oriented the way the user is looking, convert it to Euler, and its Y will tell you the angle on the vertical axis. More important issue is - you need to establish what do you mean by left and right - in a way the user is always looking forward, left and right are relative against something. It would probably be best to have a reference transform on the scene that establishes a 'forward' direction, you could then 'flatten' both forward vectors (zero out y component of the transform.forward), and use Vector3.SignedAngle(Vector3 from, Vector3 to, Vector3.up); to get a value in degrees, you can use directly - negative angle whill be left while positive will be right (possibly the other way around, depending on parameter order).

  • Related