'Unity XR integration scene objects rotate along with head movement

It all happened when I declared the camera as global of type transform. Just wanted the debug ray to follow head movement and to be placed at the center. I managed to get that but all objects in the scene just followed suit

public GameObject ground;
public Transform lookCamera;

void Update()
{
   Transform camera = lookCamera;
   Ray Ray;
   RaycastHit[] hits;
   GameObject hitObject;

 
   Debug.DrawRay(camera.position,camera.rotation * Vector3.forward * 100.0f)

   ray = new Ray(camera.position, camera.rotation * Vector3.forward);
   hits = Physics.Raycast(ray);

   for (int i=0; i<hits.Length; i++)
   {
       RaycastHit hit = hits[i];
       hitObject = hit.collider.gameObject;

       if (hitObject == ground)
       {
          Debug Log("Hit (x,y,z): " + hit.point.toString("F2"));
          transform.position = hit.point;
       }
      }
   }
}

Now I've removed the global declaration and change from this

Transform camera = lookCamera;

To this

Transform camera = Camera.main.transform;

The problem never solved. I even created a fresh new scene. Check the bindings on XRRig main camera seem nothing could help. Do anybody got any idea how to solve this?



Solution 1:[1]

I have figured out what was causing the issue in my situation. I simply had to disable the XR Device Simulator that I was using to test the XR controllers on my computer through keyboard and mouse.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aditya Tomar