SlipperyBrick Posted April 7, 2015 Share Posted April 7, 2015 I am looking at making a PCG script that will generate a level using prefabs of modular components. I am trying to figure out the logic behind this of how the script is going to work but I am running short of ideas. I actually only have one method on how to do this which I read up on a forum. You could create room templates that are prefabs. Add a short script to the prefab's main GameObject that lets you specify where the connection points are. If you want to keep it simple, you can restrict connections to the middle of each edge (top, bottom, left, right) and have a Boolean variable for each. Say you start with a prefab room where left and right are true. For the left connection, you want to find another prefab whose right connection is true, and then instantiate it next to the original room. The thread can be found here http://forum.unity3d.com/threads/structuring-procedural-level-generation.279680/ This method was on the Unity forums. I am looking to see if anyone else has some idea's or methods they would want to share on how to do something like this? I am struggling to get started Cheers. Quote Link to comment Share on other sites More sharing options...
beo6 Posted April 7, 2015 Share Posted April 7, 2015 there where some good thoughts about that already in this thread here: http://www.leadwerks.com/werkspace/topic/12063-procedural-generated-levels-using-prefabs/page__hl__procedural and i guess i would not do it much differently. put pivots to the doors where the parts can connect etc. i am just not sure how intersecting parts should be handled. If you go the Binding Of Isaac route, i guess you would not even have to worry about that, since the scenes switch completely and you can unload the other part. (or move the old part out of the way if you don´t want to fiddle with loading/saving if you are able to return to the old part. but it would eat more memory i guess) 1 Quote Link to comment Share on other sites More sharing options...
Rick Posted April 7, 2015 Share Posted April 7, 2015 Make a 3D array. Imagine a 2D tiled game. You have x and y "tiles". You are now just adding z layers (vertical layers) to that. Now in a 2D game you have tile sizes. Normally like 32x32 or 64x64 which means 32 or 64 pixels in width or height. You normally want width and height to be the same. Now in 2D land you can make bigger objects by combining multiple tiles that makes up the bigger image. Like you can make a house that is 3x3 in tiles. Now translate this all to 3D. Your prefabs are your tiles. Make them all the same size width width depth and pick a constant height value. Ideally you would make the width/height the smallest you can imagine will be needed, but for performance reasons you'll want to not have it so small. If you need bigger things in your scene then you can make prefabs that are meant to be combined together to make that bigger thing. In the 3D array just store numbers. The numbers will relate to the prefab. 1 = hallway.pfb, 2 = hallway_end.pfb etc. Then you just have some code that fills in this 3D array with numbers. On load you loop over it and do a lookup on the numbers to load the correct prefab. Each "tile" has a position (center point) and so placing your models is easy since the width/height/depth are all known. Let's say for example you pick 2cm height, 10cm depth, 10cm width for all your prefabs (just for example). Let's say 0,0,0 in your 3D "map" array is 0,0,0 in the world origin. map 1, 0, 0 means you are moving right on the x value in LE. So you just multiply 10 by that x value and that gives you the new position for whatever model is in that map. If this seems confusing I suggest looking at how 2D tilemaps are drawn and it'll start to become more clear. You could even just use 2D array to start with and just have everything at 0 height. It might be easier to understand to start with. 1 Quote Link to comment Share on other sites More sharing options...
Einlander Posted April 7, 2015 Share Posted April 7, 2015 I started doing the same with buildings, but life took over and i never finished it. http://www.leadwerks.com/werkspace/blog/120/entry-1275-building-worlds/ Quote Link to comment Share on other sites More sharing options...
Einlander Posted April 8, 2015 Share Posted April 8, 2015 Continuing the conversation from the status updates, you mentioned to you have assets already created. How are they constructed? Are they actual prefabs where walls, floors, and ceilings are already in place and you piece them together like a jigsaw puzzle? Or after you generating them at runtime? 1 Quote Link to comment Share on other sites More sharing options...
Naughty Alien Posted April 9, 2015 Share Posted April 9, 2015 ..game im working on at this moment is online procedurally generated, somewhat similar to what you asking for...here is some of the possible approaches, you may find interesting for your idea.. http://gamedevelopment.tutsplus.com/tutorials/bake-your-own-3d-dungeons-with-procedural-recipes--gamedev-14360 2 Quote Link to comment Share on other sites More sharing options...
SlipperyBrick Posted April 9, 2015 Author Share Posted April 9, 2015 Hey guys, I will put up some screenshots of the assets and prefabs. I haven't yet started the script, I have been reading through Flexman's blog of one method he uses to do this but it isn't what I am looking for. I will start a blog and get some screenshots up of what I have so far though for you guys too see. I think I am gonna need the help to be honest Quote Link to comment Share on other sites More sharing options...
josk Posted April 9, 2015 Share Posted April 9, 2015 Good link NA, I have been following these threads as I considered having the later levels of my game procedurally generated, 1 Quote Elite Cobra Squad Link to comment Share on other sites More sharing options...
SlipperyBrick Posted May 10, 2015 Author Share Posted May 10, 2015 Continuing the conversation from the status updates, you mentioned to you have assets already created. How are they constructed? Are they actual prefabs where walls, floors, and ceilings are already in place and you piece them together like a jigsaw puzzle? Or after you generating them at runtime? Hey Einlander I totally missed your post. To answer your question, yes. All models are pretty much constructed with walls, floors, ceilings already. They all piece together as you say 'like a jigsaw'. I will post screenshots later today so you guys can see the way I have made the models. Pivot points are all centred on the models at 0, 0, 0. I unfortunately had to start all over again with this project, I bought a laptop about a week ago (girlfriend complains about me being glued to my desktop and not spending time with her lol.) I thought I had backed up the whole project to my Dropbox, so I removed the project from my desktop and then realized I didn't back up the project so I lost everything I started making the assets again they are pretty much the same as what I had, I have about 4 of them so far, I am trying to plan ahead before making more. The map is going to be a train station very similar to the 'London Underground' so corridors and platforms and big spaces for ticket machines and benches etc are going to be done but I am thinking how I can break things up so the procedural generation stuff brings back interesting results for different variations of the map and also works everytime, predictability is my objective with this I am researching into the 'preparation' of PGC and the thinking behind how the models should be constructed, the way I am currently doing it from what I have seen seems to be the usual way it is done (if that makes any sense lol). Screenshots will defo come later today though, I am probably going to need a lot of help on this so expect some nagging from me guys Quote Link to comment Share on other sites More sharing options...
SlipperyBrick Posted May 10, 2015 Author Share Posted May 10, 2015 Just found this interesting paper on the control of content for procedural generation. It goes in to some nice detail from a designers perspective. Not a lengthy paper either, good for some light reading if anyone is interested https://graphics.tudelft.nl/Publications-new/2013/LLB13a/designingprocedurally.pdf Quote Link to comment Share on other sites More sharing options...
SlipperyBrick Posted May 10, 2015 Author Share Posted May 10, 2015 Ok here is a screenshot from Leadwerks of the modular components I have so far. Not a lot right now and the UV's need a lot of work so the textures are all seamless I am currently working on more. Just trying to plan how to build certain parts. This is how the majority of the models are going to be made, so each one can join up nicely to make a seamless level. Right now the pivot points are set at 0, 0, 0. I think this is probably how I am going to keep it. I was thinking of using a boolean type operation on the models so both ends of the model will have a 'true' or 'false' value so only 'true' will match up with 'true' and vice versa, the more I think about this though the more problems I think it may cause. I am probably going to work up some artwork for promotion and get my project a 'Greenlight' concept page on Steam so I can add it to the game database here on Leadwerks. I am thinking of starting a blog here also, everything is still heavily WIP but I am hoping to have the majority if not all of the models done pretty soon 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted May 10, 2015 Share Posted May 10, 2015 In my opinion, you are making things way too hard on yourself. You could use brushes to create any rooms like that, and then just populate them with model props for details (like the light fixtures). It would be faster and you'd have a lot more flexibility with your design. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SlipperyBrick Posted May 10, 2015 Author Share Posted May 10, 2015 In my opinion, you are making things way too hard on yourself. You could use brushes to create any rooms like that, and then just populate them with model props for details (like the light fixtures). It would be faster and you'd have a lot more flexibility with your design. Defo sounds much more easier, the main reason I am modelling is really for practice but I do want to get things going with this game. Maby this way would be better to get the main elements of the game done visually so I can focus on gameplay. I could get a prototype done much quicker and get some feedback on it, after that I can focus on the visuals. Quote Link to comment Share on other sites More sharing options...
Rick Posted May 10, 2015 Share Posted May 10, 2015 I think the idea was to get procedural levels which comes with the benefits of having unlimited level designs since it's put together in code with some randomness, making replayability much higher and more interesting. 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted May 10, 2015 Share Posted May 10, 2015 Oh yeah, I lost track of the conversation. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
funnygamemaker Posted May 20, 2015 Share Posted May 20, 2015 I've been looking into procedural generation to, and I was wondering with this game engine how would I create and size a GSG with lua. I dont know what api I should look for, And if I switch and use rooms that are prefabs, how would I detect where a door way would be? Quote ~Morgan Link to comment Share on other sites More sharing options...
Josh Posted May 20, 2015 Share Posted May 20, 2015 CSG brushes are really a modeling helper, and get collapsed into models when the map is run. There is no API for brushes, but you can build models from scratch: http://www.leadwerks.com/werkspace/page/api-reference/_/model/ http://www.leadwerks.com/werkspace/page/api-reference/_/surface/ 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Einlander Posted May 21, 2015 Share Posted May 21, 2015 I personally wouldn't use CSG's, they have little gotchas that appear in the oddest of places. Also texturing in the editor and in game is completely different. 1 Quote Link to comment Share on other sites More sharing options...
funnygamemaker Posted May 21, 2015 Share Posted May 21, 2015 Okay, so say if I went with a room prefab, how would I detect where a door way is, would I have to create a pivot for each entrances, so that for each differnt prefab, check and make sure that the pivots are right and move the prefab to that pivot? Quote ~Morgan Link to comment Share on other sites More sharing options...
nick.ace Posted May 21, 2015 Share Posted May 21, 2015 That's probably a good way to do it. Pivots are pretty powerful for methods like that. If they are grid-based rooms, then you might not even have to do that. Usually, grid-based approaches are easiest for procedural generation since they are easy to line up. If you are talking about adding doors after the level is generated, then the method you described would probably work best. 1 Quote Link to comment Share on other sites More sharing options...
Rick Posted May 21, 2015 Share Posted May 21, 2015 Just note that you may run into performance issues if you have a ton of entities. LE doesn't like a ton of entities so you may have to lower the view distance to be fairly low to help out the performance pending on how many entities you end up with. I know we ran into this when we were trying to do something similar with our game and making houses in a very modular way. Quote Link to comment Share on other sites More sharing options...
tjheldna Posted May 21, 2015 Share Posted May 21, 2015 Yes, the modular thing in LE didn't work for us with the size of the project we are looking at. You can keep it modular, but I recommend build your structures in your modeling program and export as much as you can as one piece. We did a lot of testing in the initial stages of our project to see what is possible. Quote Link to comment Share on other sites More sharing options...
Josh Posted May 21, 2015 Share Posted May 21, 2015 I personally wouldn't use CSG's, they have little gotchas that appear in the oddest of places. Also texturing in the editor and in game is completely different. What do you mean? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
tournamentdan Posted May 21, 2015 Share Posted May 21, 2015 For me, since you can't instance csg's I would only use csg's to block out a level for the concept phase of game creation. And then move on to regular mesh models that can be instanced or use geometry shaders to create or delete models to help cut back on the entity count. Quote Link to comment Share on other sites More sharing options...
funnygamemaker Posted May 22, 2015 Share Posted May 22, 2015 This is my first attempt for any procedural generation, and I'm very surprised that it worked with no errors. Quote ~Morgan Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.