If the new room collided with anything, then I would recycle the room. The something new was to build the new room at origin, then move it into the new proposed location and test the location using collision detection. The next step was to change my approach from finding the exit to the last built room, adding a door, then trying to build a new room at that location, to something new. Popping into Photoshop, I whipped up some very very basic textures. The door, I placed as a child in the middle of a floor tile. I made a floor quad and a door, both with their own box collider. So – I created some very basic shapes for testing. I would like to return to them once the system is working, but for now, I needed some very simple building blocks to test with. They were unique enough that I found myself hampered by their details.
The first thing I did was throw out the BigGem assets, as much as I loved them. So I stopped the blind frontal assault, sat down and rethought my whole approach. If I was going to build the room from a start point, I would also need to affect the orientation of the room before we built it.
More often than not, the room was simply building over the room it came from. This worked well, though this pattern was aligned to the world coordinates.
The code that created the rooms created them by rows from the start point. When we left off with this saga I had roughly generated random room sizes and found random start points for new rooms.
The door units are cobbled together starting with a floor tile and a slab to represent a door, with some wall units attached which simply and inelegantly overlap the walls nearest to it. The entire system is based on 1 meter square floor tiles along with wall panels at and door tiles with a foot print of 1 unit square. Let’s run the same code multiple times to see the varying results.As I continue to scratch the itch compelling me to make a randomly generated dungeon, I’ve pushed this system far enough to make random rooms & corridors connected by doors.
Here’s how to generate an integer between 5 and 10 (inclusive). You can combine the RAND() function with the FLOOR() function to return a random integer between two numbers. SELECT RAND()*10 Įxample 4 – Returning a Random Integer Between Two Numbers You can use the RAND() function as part of an expression. In this case, the function will return the same value each time if an equal argument value is provided. This allows you to influence the output of the function. Here’s an example of what happens when we run multiple RAND() functions together. The result is not a constant – it will be different each time you run it. Here’s a basic example to demonstrate what happens when we don’t provide an argument. Where N is an optional seed value that you can use to influence the result. You can also influence the random number by providing a seed value as an argument. Specifically, the function returns a random floating-point value v in the range 0 <= v < 1.0. In MySQL, the RAND() function allows you to generate a random number.