You know the length going from the red line to the top of the blue line, right? Then you can apply some basic trigonometry.
The blue line and the red line are the legs of a right triangle. Your desired line from the camera to the red line in the direction of the raycast is the triangle's hypotenuse (origin at the camera):
Given an angle,
theta between the hypotenuse and some leg of a right triangle:
cos(theta) = adjacent_leg_length / hypotenuse_length
But you don't have the
hypotenuse_length, so you'll rearrange it like so:
hypotenuse_length = adjacent_leg_length / cos(theta)
Assuming you have your
redLineHeight as demonstrated in your screenshots, here's how to get a relative vector representing this hypotenuse:
Vector3 cameraPosition = GetCameraPosition();
float redLineHeight = GetRedLineHeight();
float cameraHeightFromRedLine = cameraPosition.y - redLineHeight;
float angle = Vector3.Angle(Vector3.down, raycastDirection);
float magnitude = cameraHeightFromRedLine / Mathf.Cos(angle);
Vector3 yourNewVector = raycastDirection.normalized * magnitude;
Now that you have this new vector, you can do a check at the end of it with
float checkRadius = GetCheckRadius();
Collider hits = Physics.OverlapSphere(cameraPosition + yourNewVector, checkRadius);
foreach (Collider hit in hits) ProcessHit(hit);
Alternatively, if you have a list of hittable GameObjects and there aren't that many in that list, you can bypass the
Physic.OverlapSphere call and do a squared distance comparison on each. The advantage of using Physics.OverlapSphere is that PhysX does smart things to prune colliders it would otherwise have to check against. But if you already have that list filtered down enough, you can save on not having to call out to the native physics code. It all depends on the cost of iterating through your hittable set vs the cost of calling out to Physics.OverlapSphere. Start with OverlapSphere for simplicity, and then if you find yourself needing to cut down on physics calls, then this is one place to possibly look at after you profile.
If you need to bone up on trig, Khan Academy has some videos.