Ray ray = GetComponent<Camera>().ViewportPointToRay(new Vector3(0.25f,0.25f, 0));
To trace a line from the HoloLens. Now one would assume, that the hit of the ray would be somewhere in the bottom left corner of the users viewport. However is isn’t. The ray hits in an area of 20-30 cm arround the position it should it.
Could you provide more information please? It is very hard to understand the issue with the limited information here. It would appear to me that if you are trying to hit the left hand of the view port, I’m not sure what you mean by the 20cm to 30cm around the position? Could you clarify
OK, imagine the following:
You want to place something in the users viewport (HoloLens displays). And you want to place it somewhere in front of the user, outgoing from the position of himself and further from x and y on his viewport (HoloLens display).
I did two quick drawings to show what i mean:
The first image just shows the user with the HoloLens on. And the ray (red line) being casted.
The second image shows the users viewport (with a coordinate system) and a red dot ca. at x=0.25 y=0.25. We want to cast a ray from this position. The red dot also represents the position, where the ray we cast, should hit.
We cast the ray using this code: Ray ray = GetComponent<Camera>().ViewportPointToRay(new Vector3(0.25f,0.25f, 0));
Lets say you then place a cube at the hit location of the ray.
According to our understanding, the cube should then be visible for the user in the bottom left of his viewport (basically where the red dot is in picture 2).
This however is not the case.
Sorry we are still a little lost on what exactly you are trying to achieve. It sounds like you would like to change the origin of the ray to x = 0.25, y = 0.25 then cast the ray from that point. If this is the case then you don’t want to use Ray ray = GetComponent().ViewportPointToRay and it might be better to use a Physics.Raycast. That way you can control the origin and the direction of the ray cast.
With this line of code : Ray ray = GetComponent().ViewportPointToRay(new Vector3(0.25f,0.25f, 0)); The ray origin starts at the camera and the direction will be the x=0.25 y=0.25.
Basically this is what we want. I did some screenshots to provide further explenation:
So basically went want to cast the green one when we have the coordinates x=0.25, y=0.25.
The red one when we would have x=0.5, y=0.5. And maybe the blue one if we have x=0.75, y=0.5 (or maybe x and y switched in this case. I’m not completely sure about this one).