Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

DunGen - Procedural Dungeon Generation

Discussion in 'Assets and Asset Store' started by Aegon-Games, Mar 7, 2014.

  1. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    It should have been part of this Medieval Melee Sale, IMO. But it can't be kept on permanent sale. lol
     
  2. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    I don't think it was meant to be on sale the second time, it had it's own little spot on the sidebar and it only stayed on sale for a few hours. I assume that was a mistake. Then again, Unity didn't tell me it was going to be on sale on Cyber Monday either, so who knows.

    I'm actually thinking of permanently dropping the price, maybe to $40-50 USD. But yes, there's definitely going to be more sales in the future, although I can't guarantee that it'll be soon. I just fill in a form requesting a sale, it's completely up to Unity to decide when (or if) it actually goes on sale.
     
  3. ZombieAnomaly

    ZombieAnomaly

    Joined:
    Aug 2, 2014
    Posts:
    19
    HI, How would I call the ChosenSeed variable from another script? I'm trying to incorporate mutliplayer and I want the host to generate a seed and then just send it to the server then the rest of the clients so everyone is on the same map.
     
  4. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    I don't have access to my development PC right now so this is off the top of my head. I'll check when I get back and edit my post if necessary:

    First, you need to get access to the DungeonGenerator. If you're using the included RuntimeDungeon component, you could do something like this:

    Code (CSharp):
    1. var generatorGO = GameObject.Find("Generator");
    2. var runtimeDungeonComp = generatorGO.GetComponent<RuntimeDungeon>();
    3. var generator = runtimeDungeonComp.Generator;
    The DungeonGenerator has two seed variables, one called "Seed" which is the input you set (your desired seed). The other is called "ChosenSeed", this is a get-only property that tells you the seed a generated dungeon is currently using (which can be different from "Seed" since if the generation fails, DunGen needs to try again with a different seed).

    For your case, you'd want to take the ChosenSeed from the host after they've generated a dungeon, and pass it to the other clients who will set their Seed variable from that value. You can also just pass the same "Seed" and get identical results, passing "ChosenSeed" just avoids the same trial-and-error process on the other clients.

    Hope that helps!
     
  5. ZombieAnomaly

    ZombieAnomaly

    Joined:
    Aug 2, 2014
    Posts:
    19
    Okay! So I managed to get everything working aside from one thing! The host generates the map and then the player who joins a room should connect, generate their own map(but with the correct seed) and everything should work, yet this is not the case. I'm not sure what i'm doing wrong but i'm pretty sure the game isn't retrieving the test variable correctly. Any idea what i'm doing wrong?


    Code (CSharp):
    1.     void OnPhotonCreateRoom()
    2.     {
    3.         var runtimeDungeonComp = GetComponent<RuntimeDungeon>();
    4.         runtimeDungeonComp.enabled = true;
    5.         var generator = runtimeDungeonComp.Generator;
    6.         generator.RandomizeSeed();
    7.         generator.Generate();
    8.         status = generator.Done;
    9.         test = generator.ChosenSeed;
    10.         testing = generator.Seed;
    11.     }
    Here we generated the dungeon with a random seed and stored that variable into test.


    Code (CSharp):
    1.     void OnPhotonJoinRoom()
    2.     {
    3.         var runtimeDungeonComp_ = GetComponent<RuntimeDungeon>();
    4.         runtimeDungeonComp_.enabled = true;
    5.         var generator_ = runtimeDungeonComp_.Generator;
    6.         generator_.Seed = test;
    7.         generator_.Generate();
    8.         status_ = generator_.Done;
    9.     }
    Here we generate a new dungeon upon joining room (as opposed to creating one, meaning we aren't the host). Unfortunately the above code doesn't work unless I make the seed random.
     
    Last edited: Dec 16, 2014
  6. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Hello.

    I'm implementing some AI/Steering stuff on top of maps created by DunGen. I'm using a mix of the free "Simply A*" and "UnitySteer" packages.

    I'm wondering if it is possible to get the graph of doorway connections? I'd like to remove the A* stuff, and i could do that if i could get access to the graph of doorway connections, and the tiles the doorways are connected to, and vice-versa. UnitySteer would be more then enough, by simply steering from doorway to doorway, letting it avoid obstacles while traversing the tile.

    Any suggestions or pointers on where i could get that info? I suppose i could brute force it myself, by doing some FindObjectsOfType<Doorway>(), but i figure you must have this info someplace in the generator already.

    Thanks for the great tool!
    Jos
     
  7. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    That looks like it should work (provided the seed is correctly transferred to the clients). There are a few things I can suggest:

    1. Make sure you're using the latest version of DunGen (2.5.0) since it fixes a bug that was causing the wrong ChosenSeed to be set. You can tell if you've got the latest version because the RuntimeDungeon component should have a checkbox labelled "Allow Immediate Repeats".

    2. Make sure "ShouldRandomizeSeed" is set to false - you've probably already done this from the UI though it doesn't hurt to set it through code, just to be sure.

    3. Print out the seed that the client receives and make sure it matches what the host is sending.


    The DungeonGenerator class has a variable called "currentDungeon", which has a list of all of the doorway connections. You can access the Tile that each Doorway belongs to from the doorway itself.
     
  8. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Awesome. Thanks!
     
  9. ZombieAnomaly

    ZombieAnomaly

    Joined:
    Aug 2, 2014
    Posts:
    19

    Thanks for all of your help! everything is working great now! I was just wondering one thing, is there a way to set a minimum amount of rooms? I noticed in your demos some of them contained a room count? Anyway I was just asking because i'm getting a pretty big range of rooms, some dungeons have 20, some have 5. Maybe its just my settings or something?
     
  10. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    Just a quick question : the "DoorPrefab" field in the Doorway inspector is supposed to spawn the door i can animate? because its not working for me, i followed the instruction in the pdf but it actually is the only thing that is not working
     
  11. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    You can set a target minimum & maximum room count for the main path of the entire dungeon in the Dungeon Flow asset (it's labelled as "Length"). DunGen can't guarantee that it'll reach the minimum count though due to the trial-and-error nature of how it works.

    I think this is a bug. I tried it myself and couldn't get the door prefab to show up. It turns out the GameObject is actually there in the hierarchy (parented under the doorway GameObject), but is inactive.

    Anyway, I've put together a new Beta build (2.5.1) that should fix it. You can get it at the usual place. Changelog is in the original post as always.
     
    hopeful likes this.
  12. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    Ok so it seems it was my tile fault, DunGen actually is working perfectly!
    Thanks Dan for all the help (i know i pissed you off those days :p )
     
  13. ge01f

    ge01f

    Joined:
    Nov 28, 2014
    Posts:
    121
    Not sure if this is still on the horizon, but I just read through this thread. Back in June there was discussion about doing a grid-based system.

    In that scenario, why not just put a bounding box around rooms, and using that (rounding up to the nearest unit of your choice, like 1m) as the sizing information?

    For rooms that are grid based, they will fit exactly and can be packed densely. For rooms that are sparse or windy, they will take up more room, but have a maximum room of their bounding box size, so rooms could still be put above/beneath/beside them.

    That way nothing changes with respect to being able to put arbitrary assets into DunGen, and people do not have to enforce their assets were built with the same grid base units, and you dont have to maintain two packages.

    By the way, really enjoying DunGen. As a coder, and more of a designer at present, it's great to be able to lay out minimal amounts of configurations and get something more interesting back each time. :)
     
  14. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    Not at all. Thanks for being patient while we worked through diagnosing the problem. I think I've only had one or two support emails that have actually pissed me off, and they were from people who pirated DunGen then tried to get support from me.

    Yeah, that's still something I would very much like to do. I had started it earlier but ran in to some problems with the design, so it's in my backlog of things to do right now. We're currently at the end of a project ourselves so I don't have a great deal of time to work on adding new features to DunGen (which is why I've only been doing bug fixes and a few small features recently). Hopefully, once our project is released, I'll be able to get back to work on v3.0

    When rounding a bounding box up the the nearest grid unit, there still has to be some manual work done to the tile to make sure the doorways are positioned correctly. The idea was that doorways needed to line-up with the grid, but you could make smaller rooms as you suggested - you'd just need to extend the doorways out to the grid-snapped bounding box.
     
  15. timmypowergamer

    timmypowergamer

    Joined:
    Mar 14, 2012
    Posts:
    17
    Back on my post about wanting to control the connection chance on a per-archetype basis, just wanted to say that I finally decided to peek into the code to see how hard it would be to do. I was surprised at how easy it was. I added a ConnectionChance float to the DungeonArchetype class (and added the control to the inspector), then added about 4 lines of code to the ConnectOverlappingDoorways method. It now checks if both tiles are part of the same archetype, and if so uses the archetypes connection chance. If the tiles are from different archetypes (or not in an archetype at all) it uses the chance from the Flow instead. Now I can create some sprawling open-world areas by setting the archetype connection chance high, but still ensure that certain choke-points are not bypassed by setting the "global" flow chance to 0. I also had to add a line to make sure that it didn't connect doorways from different socket groups, as I had some doorways that were flagged as "Large" get connected to the default doorways, which didn't make sense or look right. You might want to make that change for future versions.

    Anyway, just wanted to say thanks for making your code so well organized and easy to understand. I am super impressed with how powerful this thing can be, and how easy it is to tweak to get the exact results I'm looking for.
     
    Drannach and eridani like this.
  16. ge01f

    ge01f

    Joined:
    Nov 28, 2014
    Posts:
    121
    @timmypowergamer I'd be interested in a diff of those changes, if you can post it.
     
  17. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    Someone is using rooms like 40 x 40 or 20 x 40 units? when i try to implement bigger rooms i get em overlapped more often than not. Just to understand if i made a mess with the settings...
     
  18. ge01f

    ge01f

    Joined:
    Nov 28, 2014
    Posts:
    121
    I have some 50x70x30 rooms, and they work. Theyre regular box shaped, and the doors are all at the edges.

    I made these have 7 doors, 4 at the ground level, 3 at a higher level, and this also adds height changes into the map systems. I do about 30 rooms, and it sprawls nicely.
     
    Drannach likes this.
  19. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    Ok so i made some mistake creating my rooms... strange thing is that the smaller ones are working perfectly... i'll investigate.
    Thanks a lot for the answer ge01f.
     
  20. ge01f

    ge01f

    Joined:
    Nov 28, 2014
    Posts:
    121
    I dont have the large room in this demo, because of some modeling problems that happened after I got it working, but I figured I'd share this demo with the forum:



    I wasn't sure this would work when I tried it, but I have put the enemy NPCs, barricades (crates/walls) and pickups into 3 different Local Prop sets for each Tile. This way they all have their own chances for randomization. It worked out really nicely.

    My next steps will be to give each room a "purpose" for existing (what do people do in that room?), and with this next one I'll be using another Local Prop set that has a minimum of 1 and maximum of 1 item, and then all the things that make that room special will be populated. This will have a nice effect that the room and doorways will be shared (mostly to save time while updating those), and then all the things that make that room different by "purpose" will just be a group of stuff that gets selected. A room can have many purposes, but only 1 of them will show up.

    This will allow overlapping assets in the hierarchy (position overlaps). When working with them I'll just disable their group game object, and then when I save the Tile prefab I'll re-enable them, and DunGen Local Prop randomizer will pick only one.

    This is really a great flexible system, just felt like sharing.
     
    Drannach likes this.
  21. timmypowergamer

    timmypowergamer

    Joined:
    Mar 14, 2012
    Posts:
    17
    @Drannach: I ran into a similar problem for a while, and I'm not sure if it's a bug or if it's how it was intended, but when DunGen places tiles it seems to calculate the bounding box of a tile based on the location and height of the doorways, and not the actual contents of the tile itself. At one point I had a large set-piece tile (a bridge over a river) that only had 2 small doorways in the middle. It was supposed to sort of divide the level into 2 halves, but I found that DunGen kept placing other tiles through it. Eventually I tried placing doorways at the other 2 ends, and that made it stop placing tiles through it. I didn't actually want it to use those doors, so I just made them a socket type that wasn't being used anywhere else. Eventually I ended up creating a special "No Connect" socket type that never gets considered as a valid doorway, just for this purpose. So try making sure that your larger tiles have doorways on all 4 sides, even just as a test to see if my theory holds any merit. You could also try making the doorways larger to cover the width of your tile, in case it takes that into account too (I don't think it does, but I don't have my dev PC handy to check). The width of the door doesn't actually matter when connecting 2 doorways. Just the position and socket type.

    @ge01f: Sure thing. It'll be a couple of days before I'm back at my Dev PC though, being the holidays and all :)
     
    hopeful likes this.
  22. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    Well it seems you were right, I'm still testing it but i'm not having rooms overlapped just adding a door in every wall on the bigger rooms, thanks!

    Now the last problem i'm having is that i cant generate a dungeon with more than 10 rooms more or less, it will fail 50% - 80% of the time. And i'm having 6 type of rooms with 4 / 9 doors each, should be easy to connect em.
     
  23. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    That definitely sounds like a bug. The way DunGen is supposed to construct the bounding box is by forming a box around all of the visible and collision components in the room, then moving the bounds inwards until they're in line with a doorway (but only if there is a doorway on that edge of the room). I was originally just making a bounding box around the components, but noticed that many people wanted tiles where the contents of the room sometimes protruded beyond the dooways, causing the doorways to be inside the bounds of the room, and therefore inaccessible


    I think I just responded to your email about this problem, but in case that isn't you (and for the benefit of anyone else experiencing the same problem), here's my response:

    Unfortunately, this isn't an easy problem to fix. Due to the trial-and-error nature of DunGen, it has a chance to fail and that failure chance increases with dungeon length. But ~15 rooms sounds a little low for it to be failing that often. I checked out the demo dungeon with varying lengths in the Analysis Scene (also included in DunGen) and this is what I got:

    Length: 10-20, Success Rate: 99.5%
    Length: 20-40, Success Rate: 60.2%
    Length: 40-80, Success Rate: 3.6%

    So 15 rooms sounds reasonable, it seems you just got unlucky with the way your rooms interact.


    There are a couple of steps you can use to improve the success chance for your dungeon but it sounds like you've done most of them:

    1. Never use rooms with only one doorway unless they're only going to be used for the start/end rooms.
    2. Try to minimise the number of rooms with only 2 doorways. Basically, more doorways = more options for DunGen, so it's less likely to fail.
    3. If possible, keep the walls & doorways snapped to a grid.
    4. Variation in room shapes seems to help. Having all rooms as a single shape causes failures more often, I'm not sure why yet.


    The only other thing I can suggest is to try removing your rooms from the dungeon one at a time to see if a specific room is causing problems. Sorry, it's not a very exact process, but due to the nature of the problem there isn't much information that DunGen could give to help. You could also generate a smaller dungeon and look at the results to see if any of your rooms types are making it tricky to add additional rooms.

    I'm constantly working on improving the reliability of DunGen but until I do a complete re-write for v3.0, sometimes it just doesn't work and it can be difficult to figure out why.

    Sorry I couldn't give a more concrete answer about how to fix this.

    .
     
  24. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    Ok thanks a lot for the info, as far as i can tell you, yes i'm doing most of the things you mentioned, now i'll try to remove the rooms one at a time.

    I houls also add that i'm trying to not to use the "Allow Immediate Repeats" because it spawns chains of small corridors and it's not that good. i'll keep experimenting and posting the results, maybe can help mysel and others.
     
  25. Remer

    Remer

    Joined:
    Mar 24, 2013
    Posts:
    78
    Hello,i waited for the stable release (2.5.0) but this tile doesn't work anyway :/
     
  26. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Hi, i have a problem setting up different door Socket Groups properly.

    I have 3 rooms, all the same except for the socket groups. Quadratic with a door centered on each side.
    Room_L - with LARGE sockets.
    Room_S - with DEFAULT sockets.
    Room_H - (Hub) N/S - LARGE Sockets and W/E DEFAULT Sockets.

    Length is 10-20 and branching depth & count 1-2, a very basic setup. All tiles are allowed to rotate and Allow Immediate Repeats is checked ( This would be very handy as option per tile).
    To test if the doors are set up properly i just set that one tile into a TileSet and run the analyser. ( This could maybe become become a build-in-internal-automatic feature )

    Each room alone builds with 100% success.
    Room_H + Room_L builds with 60% success.
    Room_H + Room_S builds with 60% success.
    Room_H + Room_S + Room_L builds with 4% success.

    What am i doing wrong?



    Also a little bug, at 0% success there is a Nullpointer Exception in the analyzer. Division by zero i assume.
    In Unity 5 i have this bug which seems to cause no problems anyway, probably related to the Depth Scale:

    curveT >= m_Curve[lhs].time && curveT <= m_Curve[rhs].time
    UnityEngine.AnimationCurve:Evaluate(Single)

    DunGen.GameObjectChance:GetWeight(Boolean, Single) (at Assets/DunGen/Code/GameObjectChanceTable.cs:49)
    DunGen.GameObjectChanceTable:GetRandom(Random, Boolean, Single, GameObject, Boolean, Boolean) (at Assets/DunGen/Code/GameObjectChanceTable.cs:104)
    DunGen.DungeonGenerator:AddTile(Tile, IList`1, Single, DungeonArchetype) (at Assets/DunGen/Code/DungeonGenerator.cs:401)
    DunGen.DungeonGenerator:GenerateBranchPaths() (at Assets/DunGen/Code/DungeonGenerator.cs:362)
    DunGen.DungeonGenerator:InnerGenerate(Boolean) (at Assets/DunGen/Code/DungeonGenerator.cs:195)
    DunGen.DungeonGenerator:InnerGenerate(Boolean) (at Assets/DunGen/Code/DungeonGenerator.cs:192)
    DunGen.DungeonGenerator:OuterGenerate() (at Assets/DunGen/Code/DungeonGenerator.cs:100)
    DunGen.DungeonGenerator:Generate() (at Assets/DunGen/Code/DungeonGenerator.cs:80)
    DunGen.Editor.RuntimeAnalyzer:Update() (at Assets/DunGen/Code/Analysis/RuntimeAnalyzer.cs:81)
     
    Last edited: Dec 28, 2014
  27. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    A little update : It seems that DunGen desn't like some of my tiles, but i don't know why, i tweaked em in every possible way.
    But with the "good" tiles, it works really well.
    I'm working now with a dungeon that has 143 tiles and the build is positive 40% of the time (it's really good atm in my opinion)


    I still can't solve the problem with big rooms ( 25 x 35 or more) that are overlapping. the same happens with rooms with 2 + floors.

    Keep up the good work Dan :).
     
  28. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Good? That's awesome! I cant get over 40 with a single, simple cube-room. Any tipps on how to make a good tile? :)

    Edit: The overlapping maybe occurs because you have more than one door at the same side, i think thats generally a bad idea.
     
    Last edited: Dec 29, 2014
  29. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    What's the problem? Are you getting an error? Is it just not generating?


    I haven't really done many tests using multiple doorway sockets. With more sockets, DunGen has fewer options, so I'd expect it to have a slightly lower success chance, but that doesn't explain why your success chance drops to 4% with all three rooms when the rate is 60% with just two of them.

    I'm going to revisit the way I decide if a room has failed to be added to the main path. I might be giving up too quickly - I'll have a look, and see if trying more combinations before abandoning a dungeon provides better results.

    I can't comment on the Unity 5 beta bug right now I'm afraid since I don't have access. I'll definitely be looking to make DunGen compatible with Unity 5 as soon as it comes out of beta though. From what I've heard so far, DunGen works with Unity 5 for the most part.

    That's a lot of rooms! There's definitely a bug with generating the bounding box around some rooms (although I've only been able to reproduce it in situations where not all walls have a doorway). If all of your walls have a doorway and you still see some overlapping, can you please select the room in the hierarchy and check it's bounding box (coloured red)?

    As for the success chance problem, like I said in my response to Binary42, I'll be revisiting the way I handle failure when adding a new room; so hopefully, I'll be able to bump up the success rate across the board.
     
  30. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Hi, thanks for the quick response.

    I cant quite grasp where the limitations lie. From my (obviously) naive point of view, an atomic tile, which is quadratic with a doorway on each side setup so it tiles perfectly, should be able to build an infinitive dungeon (just main path, without branching) - unless you take 3 or worse 4 turns in the same direction successively and end up in the previous created tiles.
    Could you please briefly explain how DunGen differs from my naive vision? :)

    Also i get DoorPrefabs placed twice on the MainPath when i set a Connection Chance. I guess one is set for the path and one for the Connection Chance.
     
  31. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    I poked around in the room generation code like I said I would, and noticed that DunGen actually never retries when adding a room. If DunGen fails to put down a single room anywhere in the main path of the dungeon, it scraps the entire thing and starts over. So it looks like I added the retry functionality on the dungeon level, but forgot to do the same on the room level - this is a bug that'll have been in there since v1.0 :oops:

    With that fixed, square rooms no longer have a disproportionate chance to cause a dungeon to fail, and failure rate doesn't increase exponentially with dungeon length. It now works as expected, even with >150 rooms:
    SqaureDungeon.png

    Here's a look at the change in success rates, using the Demo Dungeon at varying lengths:

    Length: 10-20, Before: 99.5%, After: 100%
    Length: 20-40, Before: 60.2%, After: 99.8%
    Length: 40-80, Before: 3.6%, After: 64%

    The one downside is that now dungeons that are doomed to fail will take longer to do so, since each failed room will be retried MaxAttemptCount number of times.



    Looking at the last couple of issues (thanks for the bug reports everyone, by the way), I think this new version solves pretty much everything, let me know if I've missed anything:

    Version 2.5.2 (Beta) - Download HERE
    - Users should notice a large improvement in success rate when generating dungeons.
    - DunGen will keep trying until it succeeds when the project is built (can still fail in the editor as a safety net to prevent infinite loops for invalid dungeons)
    - Fixed an issue causing bounding boxes to sometimes be calculated incorrectly
    - Doorways should no longer have multiple door prefabs assigned to them if the doorways were connected by overlapping
     
    Last edited: Dec 29, 2014
    timmypowergamer, Binary42 and hopeful like this.
  32. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Niceee! :D

    I also poked your code for the snake-bites-its-own-tail-problem.
    I added a weight to use the opposite door if available, so on the full weight you can easily have infinite tiles (though in a straight line ;P )

    at PickRandomDoorway in TilePlacementData i added the following lines above the others:
    Code (CSharp):
    1. [...]
    2.  
    3.             int turnChance = 50;
    4.             int rnd =  randomStream.Next(0, 100);
    5.             if(isOnMainPath && UsedDoorways.Count == 1 && rnd > turnChance) //UsedDoorways.Count == 1 checks for the door were coming from
    6.             {
    7.                 foreach(Doorway d in UnusedDoorways)
    8.                 {
    9.                     if(UsedDoorways[0].transform.forward == -d.transform.forward)
    10.                         return d;
    11.                 }
    12.             }
    13. [...]
    Though my sample is extremley hacky the Turnchance gives a nice tweakeble value not only for dungeon size but also to control if you want to have a corridor like dungeon or a more nested one. Can i have this value as an Archetype option? :)

    Edit: Pleaaaaaase. ;)
    EditEdit: I can confirm the large improvement on the success rate but i still get doubble door prefabs.
     
    Last edited: Dec 29, 2014
    hopeful likes this.
  33. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    If i'll manage to solve my problems i'll gladly share the solution! actually i dont know why some rooms are good and some are not :confused:

    Yes it seems the bounding boxes do not cover the whole volume of the tile! i'll attach some screenshots




    In those screenshots I'm using Version 2.5.2 (Beta) (The one you released today)
     
  34. timmypowergamer

    timmypowergamer

    Joined:
    Mar 14, 2012
    Posts:
    17
    A possible solution for your problem is to make your doorways taller. When it condenses the bounding box, it calculates the maximum size by finding the tallest doorway in the tile. In UnityUtil.cs inside CondenseBounds():
    Code (CSharp):
    1.             foreach (var doorway in doorways)
    2.             {
    3.                 min = Vector3.Min(min, doorway.transform.position);
    4.                 max = Vector3.Max(max, doorway.transform.position + upVector * doorway.Size.y);
    5.             }
    If you increase the y size of your doorway to cover the entire tile, the bounding box should encompass it. The height of the doorway doesn't really effect anything else (unless you are using SECTR I think). Here's an example from one of my tiles:

    As you can see, I have 6 doorways, with 2 of the sides having 2 each, and the other 2 sides with 1. The doorways are all *much* taller than the actual height of the doorway area so that they encompass the height of the big building in the corner. Realistically I could have just made 1 doorway that size and the result would be the same, but I did them all for consistency. Other tiles in the tileset have different doorway heights, depending on what's in the tile, but they all go together perfectly.

    As a side note, I was tinkering around just for fun and I found that if you change the code above to:
    Code (CSharp):
    1. foreach (var doorway in doorways)
    2.             {
    3.                 min = Vector3.Min(min, doorway.transform.position);
    4.                 max = Vector3.Max(max, doorway.transform.position + doorway.transform.up * doorway.Size.y);
    5.             }
    It lets you use vertical doorways so you can create some interesting Descent-like levels in all 3 dimensions.


    In that image, the cubes are actually hollow, with a doorway on each side (6 in total per cube). You can move the camera inside and drive it around and navigate the maze to the end. It's actually really quite confusing when you are in there :p. I use this in my actual levels on some tiles to make holes in floors/ceilings that can take you between levels of the dungeon. The only caveat seems to be that you can't allow rotation on tiles with vertical doors, as they will fail to be lined up properly. You have to make sure that both vertical doors have exactly the same orientation. Just thought I would share for anyone interested. :)
     
  35. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    From my (admittedly limited) testing, I haven't been able to reproduce this issue in 2.5.2. The new implementation of CondenseBounds shouldn't condense the bounding box on any axis that doesn't have a doorway facing down that axis, so I'm not sure what's going on here. I'll keep trying, but this is what happens when I scale up the walls of one of the rooms in the demo scene:

    TallWalls.png

    Your work-around of making the door height match the tile height should work with no negative effects, you're right that the doorway size is only really used for creating SECTR portals (and for visualization).

    It's worth mentioning that the CondenseBounds function has been completely replaced in the new beta version because it's logic was just plain wrong.


    That actually works really well, I've added the option to an internal build that I'll likely push out later today once I've fixed some more issues.

    I didn't actually test the double door prefab fix, I just assumed it was working since there's nowhere else in the code that it tries to place a door prefab. I'll fix it properly this time :p
     
  36. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    With the recent update and turnchance hack i am getting really nice dungeons (at least how i imagined them to be generated ;) )

    dungeons.jpg
    Happy customer! :)

    For the case you want to go fully automatic with that turn approach you could do a raycast for every door and see how much space there actually is. For example if the ray hit is infinity the door has a chance of 1 to be picked, if it is less then some smart picked factor, for instance the average room size, the chance to be picked develops toward zero based on the ray hit distance, aka how much space there is. For another factor you could decide to branch. And on top there is a user controlled value to tweak the strength of this "collision-avoidance" behavior.

    I admit this idea is not quickly prototyped and the usefulness not quite rateable without prototyping. But maybe something worth exploring for the 3.0 rewrite.

    Edit:
    Btw. the Depth Scale Curve Bug in Unity 5 beta is gone.
     
    Last edited: Dec 30, 2014
  37. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    And one more thing ...

    It has been, and i too can't stress enough how important it is that your geometry dimensions and most of all your doorway positions match a grid. I learned the last days with trial and error that many problems and generation failures are a result of non matching rooms. Even an offset of 0.01 from the grid can sum up in huge mismatch at the end of the generation process.

    I just grabbed SnazzyGrid and it made my tile design process incredibly easier and error-free.
    https://www.assetstore.unity3d.com/en/#!/content/19245
    It is on sale right now - and no im not affiliated with the publisher. ;)

    Edit:
    Upps sorry! I just realized that AegonGames also provides a grid-snap-tool, Easy Snap!
    https://www.assetstore.unity3d.com/en/#!/content/15042
    Go! Grab that one! x)
     
    Last edited: Dec 31, 2014
    Wavinator likes this.
  38. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    Great man, the workaround works, for now i'll just scale 1 doorway to the height of the room and that's it :) thanks a lot for the tip!
    Tomorrow i'll try the "Vertical Doorway" mod you posted, it open new gameplay possibilities!

    Instead, it seems that i can reproduce this error everytime i make a room with the walls higher than the doorways :D

    but it can also be something i do while designing the rooms, i'll keep trying too, let's see what happens :)
     
  39. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    Sorry I didn't upload the newer build yesterday like I said I would. There were two bugs that I just couldn't reproduce on my end (bounding boxes not being calculated properly, and duplicate door prefabs being placed). I tried for hours to reproduce those and just gave up in the end.

    It turns out that I'd uploaded 2.5.2 but didn't set it up correctly to be downloaded through the form on our website, so nobody even got the updates. The bugs were correctly fixed the first time. So here it is again, with some new additions:

    Version 2.5.2 (Beta) - Download
    - Users should notice a large improvement in success rate when generating dungeons.
    - DunGen will keep trying until it succeeds when the project is built (can still fail in the editor as a safety net to prevent infinite loops for invalid dungeons)
    - Fixed an issue causing bounding boxes to sometimes be calculated incorrectly
    - Doorways should no longer have multiple door prefabs assigned to them if the doorways were connected by overlapping
    - [NEW] Added a Straighten slider to the DungeonArchetype that controls the likelihood that the main path generated will be a straight line
    - [NEW] Doorways with different sockets will no longer be connected when overlapping
     
    Last edited: Dec 31, 2014
    Drannach likes this.
  40. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    The bounding box problem is solved! thanks Dan :)
     
  41. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    I couldn't reproduce the double doors either now (i already updated).

    I gave another shot on the mixed socket-doorways problem i posted above. This time i used the demo scene with the Square Room as basis, the 3 rooms are setup like above, just a copy and Socket changed. The success rate seems to drop exponentially with dungeon length:
    5-10: 100%
    10-15: 60%
    15-20: 12%
    20-25: 1%

    In my progress the next step would be keys.
    For the ease of game flow i'd like to have multiple keys of the same type than can open any door of that type. So if i collect one of 10 keys in the dungeon i can open one of the 10 matching doors and the key vanishes from the inventory.
    My hope that i just need to increase the Locks Count in the Linesegemt was not fulfilled. x) Can you give me pointer where to make changes?

    Thanks for your enduring support!
    And a happy new year! :)
     
  42. DSebJ

    DSebJ

    Joined:
    Mar 30, 2013
    Posts:
    101
    This is a great system & thanks for providing continued support.

    One thing I was curious about is why does DunGen fail to generate a dungeon ever - if the flow for dungeon generation is the simple start and end goal flow? Once a room has been placed, does it never go back and look to create a new path?
     
  43. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    621
    I'll have to look into the success rate with multiple doorway types. I haven't done a whole lot of testing with dungeons using more than one doorway socket. I expected that having more doorway sockets would reduce the success rate, but that still seems far too low to me.

    I think there may be a bug in the way locked doors are placed in the dungeon right now. The behaviour that you want should be achievable just by increasing the lock count on one of the lines in the flow graph, but I haven't been able to get DunGen to generate more than one locked door. Sorry I wasn't able to fix either of your problems just yet, I'll need to look into both of them, something's not right.


    DunGen only generates one room at a time, so it has a chance to block it's own path and fail. DunGen does go back and try again for a path that fails, but that's limited to a certain number of attempts (that you can specify). There are two reasons I don't just keep generating dungeons until it succeeds:

    1. To help indicate when there's a problem with your setup. If a dungeon fails more than 20 times in a row, it could mean that something needs changing. Failing this often just increases the time taken to generate a dungeon and you don't want to keep your users waiting.

    2. As a safeguard against infinite loops. I've occasionally made a mistake that causes a dungeon to be invalid, having a maximum number of failed attempts means DunGen won't just keep trying to generate an impossible dungeon forever.


    As of the newest beta build (2.5.2), once you've built your game (you're not running it in the editor), DunGen will ignore the MaxFaildAttempts number and just keep retrying until it succeeds. As long as you have a success chance greater than 0%, DunGen will always succeed in a packaged game.
     
  44. Sehlor

    Sehlor

    Joined:
    Feb 10, 2012
    Posts:
    199
    I bought this extension 2-3 months ago, still no luck using it ^^ tried twice, no luck.

    Does any of you guys tried it with top-down kinda game? Some screenshot would be nice :)

    BTW, 1 - 2 video tutorials about archetypes and doorways could be nice :)

    Thanks.
     
  45. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Hey Sehlor, it doesn't matter if its FPS, Top-Down or whatever. The demo dungeon and documentation is quite decent, if you tell us where you are stuck we might be able to hlep you.
     
  46. Sehlor

    Sehlor

    Joined:
    Feb 10, 2012
    Posts:
    199
  47. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    I think if you follow the DunGen video - all the steps and get that working - then try replacing a room with one from that other asset, you'll have success.
     
  48. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    First off, did you update to the latest Beta?

    You can't expect most premade assets to work with DunGen, you have to create them carfully yourself. Lets give it a shot anyway and start from scratch:
    Open the Scene Demo2 from the assetpack you mentioned

    Create Tile
    1.In the Hirachy rename "GameObject" to "SquareRoom"
    2.Drag everything except the Directional light into SqareRoom

    3. Make Entrances and delete the elements like shown in the picture DungenRemove.jpg

    4.Crate a new GameObject and name it "Doorway"
    5. Add Doorway Component to the Doorway GameObject
    6. Duplicate Doorway 3 times
    8.Drag the Doorway's into SquareRoom

    7.Set one of each DoorWay transform up with the exact values from the picure.
    Doorways.jpg

    Unfortunately the room elements are not centered to the origin, a thing you should take grate care of when you construct rooms yourself. That's why you get high fractured doorway offsets like -1.751383 and this is the source of most problems. This will work for a single room for now but you cant build a grid on such numbers that will work with different room shapes. Usually you stop right here and start building rooms yourself, if you want your rooms to work neatly with DunGen you have to take on that work. A snapping tool Like EasySnap (also AegonGames like DunGen) is a great help for constructing nice fitting, error-free rooms. Also working in an orthographic view makes things easier.

    9.Drag SqareRoom into the ProjectFolder to create a Prefab.

    Setup Dungen
    1. Create a new Tileset
    2. Add your SqareRoom Prefab to that Tileset.
    3. Crate a new DungeonArchetype
    4. add the previously created Tileset to that Archetype
    5. create a new Dungeon Flow and open the flow editor
    6. Set your Tileset to Start and End and your Flow to the line segment
    7. close the Dungeon Flow Editor.
    8. Open Window->DunGen->Generate Dungeon
    9. Drag your Dungeon Flow into the Dungeon Flow field of the generator
    10.Hit Generate!

    DungenDone.jpg

    Then, if this room works for you, you can build the next. First try if it builds a 100% just the room allone and than add the next one, repeat.

    Edit: Actually you can see in the pic for step 7 how i had placed the doorways wrong when i took that shot. However the transform values are from the corrected setup after that and are working.
     
    Last edited: Jan 3, 2015
    Drannach likes this.
  49. Sehlor

    Sehlor

    Joined:
    Feb 10, 2012
    Posts:
    199
    I didn't update to latest beta, i'll update and post my results here.

    Better go grab EasySnap i think.

    Edit: 4.6 not supported yet? :(
     
  50. ge01f

    ge01f

    Joined:
    Nov 28, 2014
    Posts:
    121
    Im using 4.6. Works fine for me.