Jump to content

Laying down large amount of trees.


mdgrigg
 Share

Recommended Posts

Hi guys, wondering if anyone could explain the easiest ways to place a large amount of trees on the terrain, preferably randomised with different heights and variation.

 

Can't wait for the vegetation took in terrain tab! "Fingers crossed"

 

I'm assuming a script would be the only way.

 

Appreciate your time guys,

 

Griggzy

Link to comment
Share on other sites

A vegetation placement tool is planned for this year.

 

In the mean time you can place your trees by hand, which is really cumbersome or by code.

 

Code wise, I would go accross all terrain vertices, have a random number choose whether to plant a tree, and as extra check also check the slope angle and/or height of the vertex.

  • Upvote 1
Link to comment
Share on other sites

A vegetation placement tool is planned for this year.

 

In the mean time you can place your trees by hand, which is really cumbersome or by code.

 

Code wise, I would go accross all terrain vertices, have a random number choose whether to plant a tree, and as extra check also check the slope angle and/or height of the vertex.

 

Thanks Aggror, my WIP is 4096 x 4096 do I am trying to avoid placing by hand, i was talking to ChrisV and he suggested creating a group prefab of trees (thanks dude) and im probably going to resort to that for now, only problem is ill more than likely have to manually adjust for terrain vertices\slope angles.

  • Upvote 1
Link to comment
Share on other sites

You could combine the 2. Prefab and code for placement. Make a prefab with a bunch of trees. Then in code loop over all these prefabs and their children (each tree) and cast a ray downward until you hit the terrain. Then adjust the tree to that point (probably a little more downward even). That way you can still manually make sure your big prefab of trees isn't on big slopes and have code adjust it. However, it'll look ugly in the editor as the trees will be hovering over the ground and only adjust at startup. You could place the code in a post processing script which would get ran in the editor, but not sure if it's that big of a deal or not.

Link to comment
Share on other sites

You could combine the 2. Prefab and code for placement. Make a prefab with a bunch of trees. Then in code loop over all these prefabs and their children (each tree) and cast a ray downward until you hit the terrain. Then adjust the tree to that point (probably a little more downward even). That way you can still manually make sure your big prefab of trees isn't on big slopes and have code adjust it. However, it'll look ugly in the editor as the trees will be hovering over the ground and only adjust at startup. You could place the code in a post processing script which would get ran in the editor, but not sure if it's that big of a deal or not.

 

Good idea, thanks Rick I'll look into it.

Link to comment
Share on other sites

  • 2 weeks later...

This should now work in the latest beta

 

function Script:Start()

 

--Adjustables, size and treemodel

local terrainsize=4096

local number=2000

local model=Model:Box()

model:SetScale(1,50,1)

 

--Find the terrain ( I know, but currently the only way )

local world=World:GetCurrent()

for i=0,world:CountEntities()-1 do

if world:GetEntity(i):GetClass()==Object.TerrainClass then

self.terrain=world:GetEntity(i)

tolua.cast(self.terrain,"Terrain")

break

end

end

 

--Put "trees" at random positions

if self.terrain then

for i=0,number-1,1

do

local m=model:Instance()

local pos=Vec3(Math:Random(-terrainsize/2,terrainsize/2),0,Math:Random(-terrainsize/2,terrainsize/2))

pos.y = self.terrain:GetElevation(pos.x,pos.z)

m:SetPosition(pos)

end

end

end

 

trees44.png

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...