Why is raycast inaccurate from afar?

i have this simple raycast

if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out var hit))

its supposed to hit the terrain from the sky. when the camera is near it works, but when its distant its jittering with gaps between the points.

its jittering with gaps between the points.

What exactly do you mean by that? A raycast only returns a single point, your hit point. Your mouse position does only have a per-pixel accuracy. So even when you move your mouse only a single pixel and do another raycast, it has to be “one screen pixel” apart. In a perspective camera things gets smaller at distance, so naturally the projected distance gets larger.

Points are infinitely small, so it’s not possible to have two points (which are not identical) without a distance between them. At a near distance from the camera that distance may be smaller than a pixel, but it doesn’t have to.

Not sure how we can help here further. We don’t know what kind of grander problem you try to solve here. So it’s impossible to suggest a different approach.