Random Assets Placer – BGE Script
Here is another nicely done script by Cotaks from the BA forums, this script called “Random Asset Placer” spawns objects that you have defined on random locations(with random orientation) on the terrain. It does an 8 directions ray check for each object before it gets placed, in this way it keeps objects from being overlaped.
This script does not keep the placed objects once the BGE is stopped (altough you can use a save/load script for that) but if you think about it, this is not the problem for short games when you do not need to save progress, or maybe not needed when the progress is only saved when you reach certain point in the game, so in this way you can avoid the player to see different prop placement on scene. And as far as I can tell, you need to wait untill the script has finished with the prop placement, so maybe would be a good idea to keep busy the player with some activities or in some indoor area, ant then when finished let him out.
The script came in a Blend file, wich already have several sample models like trees, grass, flowers, trunks and rocks so once you download the file you only need to execute the BGE and see the script in action, just like in the animated gif above.
First time testing the file
First of all, get the file here (take a look in the post for updates) and open it in blender, and press P key in your keyboard and wait untill the scripts finish all the prop placement.
If you want to change settings to add more quantity of props then modify the values “tree”, “stone”, “flower”, “flower2”, “tree_trunk” and “grass” then execute the BGE again and wait.
There is also a way to avoid object placement in certain areas, to do this the only thing needed is to place an object in some specific area and, since the script uses a “ray check” to avoid overlapping objects, this way you can specify prop-free areas for roads, buildings, etc.
Just in case you are wondering if Occluders works with this, the answer is yes. Also if your assets have some LOD model it will work as usual.
In order to use your own assets you only need to name correctly each of your assets (upper part left image) all assets are already named and ready to be placed in the ground, now it is time to change the dictionary name list in the script (bottom part of image). Just make sure the name is the same as the asset.
When it comes to performance I would sugest to disable collisions for the trees and then add some geometry collision (by parenting – Ctrl+P) to improve performance while running the game.
Once I’ve defined the assets I used a old scenario for testing purposes, here I only imported the script and the empty objects used with the script (at this moment I’ve already modified the script with the dictionary names) and then I execute the BGE and here is the result:
There is a lot of objects on scene but since collisions for trees were disabled and added a more simpler geometry colision there is no much calculation to do in that regard, so the performance is fine I do recommend to you to read more about this topic because this is one of the most underated areas when it comes to the BGE performance.
And well that’s all and hope you find this usefull.
Get the blend file here