I am trying to use a non-centered crosshair in an AR app as shown here:
I am using Vector3 cameraPoint = camera.ScreenToWorldPoint(new Vector3(cursorPos.x, cursorPos.y, 0.2f));, where cursorPos is the screen position of the cursor. However, when I make a Raycast to detect collisions using cameraPoint as the ray origin, the origin position does not seem to be at cursorPos. Instead, the Raycast origin seems to be very close to the center of the camera. The code for the Raycast is ```
Physics.Raycast(cameraPoint, camera.transform.forward, out RaycastHit hit, Mathf.Infinity, layerMask)
I also prefer KirillKuzyk’s version, that should handle everything.
Just to clarify where your problem was:
Your ray always shoots in perfect camera.forward direction. Unless you have an orthographic camera this is only correct for the camera center. On perspective cameras the ray direction points more outward the further you are from the center.
I was trying to solve a similar problem, but never found ARCamera.ScreenToWorldPoint in ARFoundation 3.1.3? Is this available in the latest ARFoundation by any chance?