Make the terrain ignore Raycast if in between Camera and Player?

I’m trying to get my Camera script working. It uses raycast from the Camera to tell the player where to Aim. However, some times, because the terrain is uneven the camera dips behind the terrain which makes the player look at some point behind him, insted of ahead of him.

I was trying to find a solution, and I wish I dont have to write a script that moves the camera around as it hits the terrain, since I want the camera to remain on the same place. I like the transparency effect that the camera undertakes when it goes behind a wall, but I can’t figure our how to raycast like this. I was hoping something of the sort: make the patch of terrain in between player and camera ignore raycast, or something of the sort… Any ideas? thank you.

Here are some images

Here is a good behaviour. Player is aiming at mouse point.

But when I go behind a terrain wall, it looks towards the camera

Well, when you raycast from the camera toward the player, if the distance is less than the distance from the camera to the player, it would be behind the player and you can throw out the value, right?