Does anyone know a better way to do this?

ahh…Maybe it’s not a question, I just thinking the method to make the effect all night.
I saw a game which named"Vista Golf", The first picture is the game scene.

but when the golf is blocked by tree. (I know the function is A Raycast from camera to golf)
There is a sphere area of the tree will be transparent . Just Like the second picture.

It’s not all part of the tree will be transparent. It’s look like a sphere area will be transparent.

Does anyone know how to do that? (Maybe it related shader.

Yup, a shader is in order to do that. The best way is probably to make sure the ball is always centered by the camera and then use world space coordinates to set the pixel’s alpha value.