My cam is in orthographic view mode and I am trying to get the terrain coordinates for a specific screen position. Using ScreenPointToRay and raycasting works great when orthographic is set to false but now, in orthographic mode, it always returns the same Vector3 no matter what screen position is used for the input? Anyone knows how to resolve this?
I have a feeling I know what’s going on, can you paste your raycasting code?
If you’re using the camera’s position as the start and the ScreenPointToRay’s direction vector, that would work fine in non-orthographic mode. However, when ortho is on, the origin point will be the part of the ray that changes while the direction stays the same; if you’re still using the camera’s position as the origin it’ll always gives you the same resulting ray.
var scrPoint : Vector3 = Vector3(x,y, 0);
var ray : Ray = Camera.main.ScreenPointToRay(scrPoint);
var hit : RaycastHit;
if (Physics.Raycast (Camera.main.transform.position, ray.direction, hit)) {
var hitPoint : Vector3 = hit.point;
}
How can I change the origin point? What I am trying to do is capture a 1024x1024 top/down screenshot and then use the 4 “corner” screen coordinates to get the terrain coordinates.
var scrPoint : Vector3 = Vector3(x,y, 0);
var ray : Ray = Camera.main.ScreenPointToRay(scrPoint);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {
var hitPoint : Vector3 = hit.point;
}