Placing Trees

Does anybody know how I can scatter my trees across my landscape above a certain height or which code to use for it?

Use ray cast and mouse picking.

He means automatically I guess.

yes that’s what I mean

Scattering vegetation in such a way that it appears to have grown naturally is tricky - there are a lot of factors that influence where plants grow, how large they get, etc. Fortunately there are fairly straightforward randomness patterns that give a very convincing placement. I want to say Poisson noise looks good for vegetation placement but I wouldn’t swear to it. That will give you the x/z (horizontal) placement of trees. Height is easy - once you know the horizontal positioning of your trees, look up the height at that position (either from the heightmap + some math or by casting rays straight down onto your terrain). If it’s above/below/between heights that you want trees in, place the tree. Otherwise skip that tree and move on to the next one.

1 Like

There is no built in function, but this is the way I did it.


The link for the code isn’t working. I brings me back to the main page.

I’ve never done this before, but would it work if you used the function from that tree random site, and spawned all the trees really high (so it dosen’t touch the ground), spawn them in, cast a ray y-axis downwards to the terrain, get the distance then move that distance downwards plus a little more just for natural being, would that work (and would it be wise?)?

EDIT: Stupid me, not reading the rest of the thread. Nevermind.

The best way I know is how @pspeed describes it in his grass / tree plot code.

1 Like