- Home /
Placing trees randomly across a large terrain
I'm wondering what would be the best way to place a bunch of trees over a large terrain. I have three different types of trees and I'd like them to be scattered around the map. Also I do have size variations of these trees. Is there any way to take all of these objects and duplicate them and scatter them around in random positions?
Thank you!
Good day. You should make a script using
Instantiate()
Random.Range
Answer by Baalhug · Sep 26, 2018 at 03:00 PM
There are two ways to accomplish that:
Using trees as objects
Using trees as terrain items
In both solutions (or at least in solution 2) you must know how terrain works. Terrain is a 2D matrix where every "cell" or point of the terrain is an element on that matrix. Every element has info about height of that point, texture, terrain items as grass or trees...
So in the first solution you can do that in 2 ways:
a) locate randomly a raycast emitter above the terrain, raycast in y axis down and place the tree object where the raycast colides with the terrain.
b) find randomly a 2D point of the terrain (x, z), get its height, convert it to global position (y) and place the tree object.
And in the second solution is the previous b) solution but instead of placing a gameobject you add a terrain tree to that matrix point, or terrain coordinate
Your answer
Follow this Question
Related Questions
Crossword game - How to start a word on a random location of players choice 0 Answers
Random object spawn? 1 Answer
Object Spawner acts really badly, 0 Answers
Beginner : Random gameobject from array 2 Answers
Network: Random spawn 1 Answer