August 24, 2015

LED Inside Development – Procedurally Generated Laser Terrain

Here’s an under-the-hood look at what the background laser-grid terrain looks like as it’s being procedurally generated inside the Unity editor.

THE GIST OF HOW I’VE IMPLEMENTED IT:

THE ARRAY:

The main information for the terrain is stored in a 2-dimensional array of integers. Each entry in the array corresponds to the height of the x,y coordinate on the laser grid. So if I want vertical line 10, point 20 I would reference the array as grid[10][20] = 5, setting the height at that point to 5.

THE ALGORITHM:

The algorithm for at its most basic is pretty simple. To make lines procedurally generated, each new line that’s generated looks at the previous line in the array and decides whether or not to continue the height values, be flat, or generate new height values, based on some random values and various other variables, such as max height and length, game level, etc.

THE LINES:

After the array values get procedurally generated I Instantiate the line renderers, and at each point on the line, set the y coordinate of the point to be what ever the value of the array is at the corresponding point. And then the line points keep updating based on new values in the array every time one line is removed and another is added.

Any question, feel free to contact me.

Look for LED coming soon to iOS.

Leave a Reply

Your email address will not be published. Required fields are marked *