Trees.

So i have 3 different tree models and within my game i have green “walls” in which i want the trees to spawn, whether thats in the same position each time or random positions that doesnt matter (as long as the view of the path is not blocked either is fine. also i said “walls” because they’re not walls but its raised 0.2? above the path from memory.)

i was hoping to find a script to help as i dont really want to place 50+ trees by hand and have all of them listed in the hierarchy; makes it messy and everything is stored in empty game objects as is.

I’m not quite sure i understand what you are looking to do. From how i understand it you basically have a road with grass strips on both sides, or something along those lines, and you want to place trees on those stripes but dont want to do it manually and dont want each tree to take up a separate gameobject?

If that’s about right, i would get the boundries of these stripes and use an algorithm like poisson disc sampling to determine the spawn locations for the trees. Poisson disc sampling is basically an algorithm for stuffing circles into a square. Using the radius of your trees as radius for the circles would guarantee no overlapping. Using the calculated spawn positions, you can then instantiate objects at these positions and optionally combine all their meshes into one object.

so the walls and floor are all made out of cubes (instead of using terrain or planes as a style choice? - it was the easiest way i could think of doing it). the game itself is isometric and the walls surround the path as seen in the screen shot; ive added in the 3 styles of trees as placeholders for the moment - they also aren’t scaled properly as of yet

6084774--660429--upload_2020-7-13_22-6-55.jpg

as seen within the screenshot, the chest is “closest” to the camera yet still surrounded by walls. with the function you said would i put those specific blocks in a separate empty game object and then just specify what game object to apply it to?