Jump to content
  • entries
  • comments
  • views

Random generated Forest: About performances.





Here are a few thoughts about finding the best way to create  a dense forest, with different models, quickly, dense and allowing good performances by walking and driving.


          I got good results but not by driving and I find that the collision checked causes the lost of 40 FPS (from 60 by to 20) making the game unplayable.

          Sure this depends on the view range and the density.

          I could get such a good beautiful looking map, allowing fast driving, but NOT allowing collision enabled, so that was sadly a no go.


  • I tried on a another map to write a little script allowing a random generated forest with 2 colliding trees models and making the not colliding vegetation with the vegetation tool.

          I obtained good results, possibly ok to be used in a game or a part of.

          The positive thing is that you can rotate the generated trees in x and z axes too, or changing the basis height easily, making a more realistic forest.

          There are performances limitations with this method too for sure: not the collision (setting collision to none didn't actually change very much regarding FPS, strangely?) but the density and the                      global range you wan't to be covered with trees. So it stays totally impossible to cover all the map (1024) with trees if you wan't a dense forest, like in the video here, with this method. The                            vegetation  tool should be better for covering all the map, if requested.


          But I found that I could create little dense forest allowing faster driving through. That's cool.

          I expected too much from setting the view range to medium or far. I thought that not rendering the trees that are far away would be equal to a none performance cost. Sadly it is not like this.

         So if the generated forest is big and very dense, even if invisible because far away from the player (by setting medium view range), the FPS are sinking drastically. Strange ? What/Where are the                 performances gone for?

         Another problem with this method is that the nav mesh will not be able to assimilate the trees as they are build in the start function. Except you generate the nav mesh after this from the script...

         Car lights are not supported, FPS sinking immediately under 20. Perhaps can here something be done with shadow disabling? Not tested. 

         Light are ok if the forest is not so dense. (but especially when the forest is dark and dense are the car lights really useful!)


  • Conclusion, this tool script is ok for making little forests allowing fast movement and looking more diverse and realistic in my opinion...
  • It is possible to add an if statement on the Terrain:GetSlope() and/or GetElevation() to choose if the trees should be summoned or not depending on the Height and Slope of the map, same options as in the vegetaion tool.
  • The GetTerrain() function runs with the spline tool - but you can find the terrain using a selection with if GetClassName()=="terrain" on all entities on the map until it find it.
  • You can summon all what you want with this, randomly, add more options... Rocks, mushrooms, flowers whatever.
  • Using Terrain:GetElevation() is a much more powerful as with Pick()
  • Script and video showcase following + beautiful screenshots done ingame with this tool:









-- This script is used to summon random trees in the specified area around the entity that carries the script.

Script.enabled=false --bool
Script.Rayon = 200 --int 
Script.Densite = 10--int 
Script.PathModel = "" --path "Tree model" "(*mdl):mdl|Models/Nature"
Script.PathModel2 = "" --path "Tree model2" "(*mdl):mdl|Models/Nature"

function Script:Start()


    if self.enabled== true then

            local pos = self.entity:GetPosition()
            local i=pos.x-self.Rayon
            local j=pos.z-self.Rayon
            local tree1=Model:Load(self.PathModel)

            local tree2=Model:Load(self.PathModel2)

--            tree1:SetViewRange(Entity.MediumViewRange)
--            tree1:SetOcclusionCullingMode(true)

            local terr=GetTerrain()
            local pickInfo2 = PickInfo()
            while j < pos.z+self.Rayon do
                while i < pos.x+self.Rayon do
                    local arbrex=Math:Random(-8,8)
                    local arbrez=Math:Random(-8,8)
                    local arbrey=Math:Random(0,-5)

                    local Rotax=Math:Random(-10,10)
                    local Rotay=Math:Random(0,360)
                    local Rotaz=Math:Random(-10,10)

                    local scalex=Math:Random(1,2)
                    local scalez=Math:Random(1,2)
                    local scaley=Math:Random(1,2)
--                    world:Pick(Vec3(i+arbrex,pos.y+100,j+arbrez),Vec3(i+arbrex,pos.y-100,j+arbrez), pickInfo2, 0, true, Collision.LineOfSight)

                if terr:GetSlope(i+arbrex, j+arbrez)>self.MinSlope then
                    local arbre=tree1:Instance()
--                    arbre:SetPosition(pickInfo2.position+Vec3(arbrex,arbrey,arbrez))



--                    world:Pick(Vec3(i+arbrex,pos.y+100,j+arbrez),Vec3(i+arbrex,pos.y-100,j+arbrez), pickInfo2, 0, true, Collision.LineOfSight)

                if terr:GetSlope(i+arbrex, j+arbrez)>self.MinSlope then
                    local arbre2=tree2:Instance()
--                    arbre2:SetPosition(pickInfo2.position+Vec3(arbrex,arbrey,arbrez))
                    i=i + self.Densite

                j=j + self.Densite





  • Like 3

1 Comment

Recommended Comments

Add a comment...

×   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.

  • Create New...