Week 4-5 Generating the Layout

I am writing this in Week 8.
Stressed a bit getting everything to work, I preferred to work on the code than write an update in regards to my progress, as I am writing this 17 of November most of the code now works.

So my initial idea with the random layout, was to generate a mesh of planes of random size rotation and position to indicate where the rooms can be placed.

Bellow is the initial algorithm for the layout generation:


Creating the Starting area
1.    Create a plane from the dimensions given for the starting area
2.    Place the starting room in it‘s given location.
3.    Add the starting room's exit point location to the open_exits List.
Create the Layout
4.    Create a plane of  random dimentions between 1/32 to 1/64 (theoretical estimate)  of the max area.
5.    Rotate the plane randomly 0-180 degrees.
6.    Select a random point withing the existing layout ( in first attempt the layout is the starting space).
7.    Examine if  the plane is at least 30% inside the existing layout area and at least 30% outside the existing layout area. If not repeat step 6.
8.    Merge the plane to the existing layout.

9.    Repeat  steps 4-8 until (layout area)/(max level size) is greater than the layout level percentage given in the editor.


The algorithm for the starting points remained the same and I added the ability to add more than one rooms in the starting scene (e.g. temple room). The algorithm for creating the layout though change as I started implementing it. I think the most important lessons i took from these two weeks were:

  1. Sometimes controlled randomization is better than uncontrolled randomization.
  2.  If something is random it can still follow rules in order to save on resources and performance.

In regards to my first statement when I first created the plane I had the length and width completely random between a min max value. While applying a  plane upon the other, I noticed the most boring and low quality layouts were created when the plane's had almost square dimensions (width ≈length)
So by randomizing only the length and setting the width to a third of the length the generator produced much more interesting layouts.


If something is random it can still follow rules in order to save on resources and performance. Initially  I wanted to attach one plane upon the existing layout and have the plane a percentage inside the layout and a percentage outside.This would require me to  create and record two groups of points, one with the newly created plane points and  the other with the current layout points and examine their common points then create the percentage based on the area of our plane.
 Instead of doing that I preferred to record the corners of each plane and place the next plane upon one of those points. In order the corner points to be recorded they needed to fulfill two requirements.

  1.  that the points were within our labyrinth's dimensions
  2. that the points were not  above the existing layout. This was done so that the layout extends as planes are placed and avoid to placing planes in the center area of our layout. Two raycasts were used above and beneath the points to examine if the raycasts hit the Layout.
Bellow is a video showing just that



Calculating the Exit plane

Satisfied with the generic layout creation, I next moved on to to calculate the plane were the exit room would be placed. To achieve this and maintain user flexibility. The user sets 2 points that form a line. That line is used to place raycast points on segments of 10 to check if  a plane is under that line. If that is true then it's market purple and stored in a list of possible exit planes, then it randomly selects one from the list and marks it red as the selected exit point.



The final Algorithm for this part was:

Creating the Starting area
1.    Create a plane from the dimensions given for the starting area
2.  Store that planes corner points in a list of Points.
3.    Place the starting room in it‘s given location.
Create the Layout
4.    Create a plane of  random width between min-max defined by the user and length is 1/3 of that width.
5.    Rotate the plane randomly 0-180 degrees.
6.  Randomly select a point from the list and place the plane upon the selected point. 
7.  Add the newly placed planed corner to the list if a) the points are within labyrinth max dimensions and b) the point is not above the current layout.    
8.    Add the plane to the existing layout.
9.    Repeat  steps 4-8 until (layout area)/(max level size) is greater than the layout level percentage given in the editor.
10. Scan across the the set line to find the planes across it and store them in a list.
11. Randomly select one of those planes to be our exit plane and rename it.

This Procedure was relatively easy and completed withing the time given.

Comments

Popular posts from this blog

Player stats and brightness.

Testing the PLG

More work done on the interface, saving data.