We were working on a post-apocalyptic desert environment for our game “DinoRancher” for our 5th round of BVW (Building Virtual Worlds – a core course at the ETC, CMU). For this game, we needed a lot of random objects like different types of cacti, different parts of machinery like engines, an assortment of gears and other such stuff to be placed in our environment. However, the gameplay environment as a whole was pretty big and randomly placing such a huge collection of objects (we had at least 15 different types of random objects that needed to occur at different frequencies) manually was not a good idea.
Developed using: Unity, C#
Team size: 5
Role: Programmer
Hence, I came up with the “randomplacer” script to do this for us.
The script takes in the number of game objects, the bounds within which the game objects need to be placed, the overall density of placement and the relative frequencies of each object’s occurrence. Once this script was run, the game objects were generated as needed with random positions and rotations.
Improvements made:
- The script now runs in editor mode.
- A slider has been added for the density variable to make sure that people who edit the values will not go above the recommended limit.
- The generated objects are now put under one game object to make editing easier.
GitHub:
https://github.com/sunilnayak133/randomplacer/blob/master/randomplacer.cs
YouTube:
A video demonstrating the script working in editor mode.
DinoRancher Demo:
A video demonstrating the actual game (DinoRancher) that this script was used for. The cacti and other random debris that can be found on the terrain was generated using this script and not hand placed, thereby saving a lot of time.