How to make a "See Behind Walls" effect on terrain trees

Hello,
is it possible in some way to make the tree in front of the camera transparent like in this example with simple gameobject?

I’m stuck on how to retrieve the tree in front of the camera, as far as I know there is no way to obtain it via raycast

You can get the position of tree instances from TerrainData. Then maybe have some code to compare tree position with camera position plus some offset?

TerrainData.treeInstances will give you an array, and then each TreeInstance in the array has position information.

Of course the downside here is that you’re having to compare against all the trees. Might be feasible to feed the tree positions into a spatial data structure to make the comparison with camera position faster.

Another approach could be, Instead of trying to identify and manipulate individual tree instances, to apply a transparency effect based on proximity to the camera. The closer the tree is to the camera, the more transparent it becomes.

1 Like