ViewportToWorldPoint doesn't work as expected

Quick explanation: I use ViewportToWorldPoint to find the corners of the screen. However, the resulting points are not situated in the corners.

dist = Camera.main.transform.position.y - transform.position.y; // Camera above player
topLeft = Camera.main.ViewportToWorldPoint(Vector3(0,1,dist)); // Get top left point?
topRight = Camera.main.ViewportToWorldPoint(Vector3(1,1,dist)); // Get top right point?

startPoint = topLeft; // These are the start and end points for a lineRenderer line.
endPoint = topRight;

I think this can be shown best with pictures (sorry it’s a bit huge).
First image is in-game - the line is misaligned at the top. 2nd and 4th images show how it extends past the edges of the camera. 3rd image shows how it’s correctly aligned on one axis. I am utterly confused. Any ideas? Thank you.

alt text

The distance is from the camera to the “universe” plane, but the distance from the camera to the corners is larger. You could use the following:

var thePlane = Plane( Vector3.up, Vector3.zero ); // The XZ plane the game is played on
var ray: Ray;
var dist: float;
ray = Camera.main.ViewportPointToRay(Vector3(0,1,0)); // topLeft ray
thePlane.Raycast(ray, dist); // Find the distance to top left...
topLeft = ray.GetPoint(dist); // Get the actual topLeft point 
ray = Camera.main.ViewportPointToRay(Vector3(1,1,0)); // topRight ray
thePlane.Raycast(ray, dist); // Find the distance to topRight...
topRight = ray.GetPoint(dist); // Get the actual topRight point 

EDITED: Yes, this is very similar to your last code - an edition of it, to be more precise, but using the rays to find directly the topLeft and topRight points at the plane level.

ViewportPointToRay works fine - it must be declared not guilty. I suspect your problem is elsewhere: something in this script or any other is causing the shift. Where do you calculate the points, Start or Update? If in Start, something may be shifting the camera or the linerenderer object after the points are calculated (not sure if moving the linerenderer object may affect the line position). If in Update, the line should keep the correct position relative to the camera - again, unless something in another Update is doing the shift.