Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'World Building' started by newlife, Aug 16, 2023.

  1. newlife

    newlife

    Joined:
    Jan 20, 2010
    Posts:
    1,050
  2. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    55
    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.

    https://docs.unity3d.com/ScriptReference/TerrainData-treeInstances.html
    https://docs.unity3d.com/ScriptReference/TreeInstance.html

    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.
     
  3. newlife

    newlife

    Joined:
    Jan 20, 2010
    Posts:
    1,050
    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.
     
    mattb-unity likes this.