Line Renderer to Screen Point

What am I doing wrong? I’m trying to draw a line that starts on a game object in the world and ends at a specific pixel location on the screen.

lr.SetPosition(0, gameObject.transform.position);
        Vector3 endPosition = Camera.main.ScreenToWorldPoint(new Vector2(30,165));
        lr.SetPosition(1, endPosition);

lr is a LineRenderer… obviously.
The line starts on the object, but then draws up to the camera and is as wide as the screen. (I want it to draw to the pixel location 30,165.)

Help? Thank you!

ScreenToWorldPoint takes a Vector3, not a Vector2. It’s accepting the Vector2 because Vector2 implicitly converts to Vector3, but it fills in a 0 for the Z field, and ScreenToWorldPoint uses the Z to mean “distance from the camera”.

You want to make that a Vector3, and the third number should be similar to the distance from gameObject.transform.position to minimize artifacts. I suspect that it’s always gonna look a little weird, so you might consider an asset like Vectrosity that renders better-looking and more-versatile lines than LineRenderer.