Adventures in Amateur Civil Engineering : Part 2

Adventures in Amateur Civil Engineering : Part 2

Part 1 can be found here.


 

So when I last left you there was a lot of talk about how I’d created the basic data structures that I’d use to generate my city but not a lot on the  the implementation of the algorithm, and that’s mostly because at the time of writing my last post nothing was finished. Luckily I’ve had a chance to really dig into code since my last post and I’m proud to say that procedurally generated cities are functioning.

ScreenShot00037

They ain’t pretty but this was just a first pass. Right now I’m mostly interested in getting roads to meet up correctly and spawning buildings that face the right direction. As I continue down this road I plan to build on to the functionality a lot. Soon sidewalks and foot paths and even plant life might make it into game but you have to start some place.

So to begin let me correct a few things I got wrong last time. First of all the math for the get and set methods on my pseudo 2 dimensional array that I posted last time should actually look like this:

getFunction_Fixed

There’s nothing like putting your work up in the internet and then realizing you did it wrong. The problem here is one I ran into all over the place and that is that unlike almost every programming language I have ever used arrays in unreal engine start at 1 not zero. Seems like it should be a simple enough thing to remember but it tripped me up all over the place.

Once I’d fixed all of my “Arrays start at 1” errors the next thing I had to do was spawn my quadrants based of the schematics I had generated in part 1.  I started by creating a few basic quadrant shapes.

QuadrantT

Quadrant4way

I’m not going to post them all, but I created a quadrant blueprint for each of the possible quadrant shapes. I made these out of just a bunch of cubes and some simple textures.  Eventually I can swap these out for actual meshes but these will do for now.

Next I needed to do was to spawn buildings at the right coordinates within each of these quadrants. I could probably have used math to determine the exact center of each tile in the quadrant and the rotation, but as seeing as these things are already going to be spawned all over the place and in different rotations, I figured the simplest way to do this is to just create scene components on each of the quadrants where a possible house could be. Then once the quadrant is in place I just get the world transform of that component and spawn a house there. saved me tons of time and headache.  I’m not sure if this is best practice but It made my life a lot easier.

That’s basically all it took to get this running. If you have any questions let me know. I’ll leave you with a few more screens of the final result.

 


Comment on this post!