Hallway Test
 LorrMaster42
 Posts: 66
 Joined: Thu Dec 24, 2015 12:09 am
Hallway Test
I decided to jump into blender and try out some modular hallways to see how they looked ingame. I made a straight, corner, threeway, and fourway piece and put them together.
https://youtu.be/nYuWz7c2ZDw
https://youtu.be/nYuWz7c2ZDw
 Interkarma
 Posts: 6137
 Joined: Sun Mar 22, 2015 1:51 am
Re: Hallway Test
This is cool! It's going to be exciting to see what the community does with Daggerfall Unity as it matures and the modding side of things gets refined.
 LorrMaster42
 Posts: 66
 Joined: Thu Dec 24, 2015 12:09 am
Re: Hallway Test
I've been experimenting with different hallway pieces to try and see how much variation I can add to a single set. Right now I've created a couple models with different lower wall and ceiling parts that can be swapped out in different combinations. For example, one dungeon might use "ceiling type 1" while another might use "ceiling type 2" with each one using the same type of floor. I'd love to hear what I could do to make different combinations more unique from one another.
I've also been wondering how the game identifies and loads dungeons. I'm still not very good with Unity, but given some time I think I could manage to create a small procedural dungeon genorator.
I've also been wondering how the game identifies and loads dungeons. I'm still not very good with Unity, but given some time I think I could manage to create a small procedural dungeon genorator.
 LorrMaster42
 Posts: 66
 Joined: Thu Dec 24, 2015 12:09 am
Re: Hallway Test
Got started on placing objects into Unity through scripting. Right now my script is running in an empty Unity scene and just places down 1way tile pieces randomly along a 3dimensional grid.
Currently I'm trying to let the system add as much variety as possible to the individual pieces, so I decided to split the hallway tile into separate, interchangeable pieces that the system will select individually. Right now I have 2 floor pieces and 2 ceiling pieces, which can allow for a total of 4 different combinations.
Currently I'm trying to let the system add as much variety as possible to the individual pieces, so I decided to split the hallway tile into separate, interchangeable pieces that the system will select individually. Right now I have 2 floor pieces and 2 ceiling pieces, which can allow for a total of 4 different combinations.
Spoiler!
 LorrMaster42
 Posts: 66
 Joined: Thu Dec 24, 2015 12:09 am
Re: Hallway Test
Made a bunch of adjustments to it. Now the system can store multiple models that share the same design together (so straight walls and corner walls of the same design can be grouped together). I am now working on the actual design of the dungeon and how the models will be placed.
One thing I'm struggling with is how to go about creating the seed. I've looked up a couple random number generators, but I can never understand the code for it or how to get a good output from a range of values. I'm also not sure what is the best way to use the seed once I've got it working.
One thing I'm struggling with is how to go about creating the seed. I've looked up a couple random number generators, but I can never understand the code for it or how to get a good output from a range of values. I'm also not sure what is the best way to use the seed once I've got it working.

 Posts: 839
 Joined: Mon Nov 30, 2015 6:32 pm
Re: Hallway Test
Warning: This turns into a minirant on statistics at the end. Fortunately, you can stop reading after the paragraph after point 3) The next paragraph is a short intro to how to use cryptography, and after that, the minirant.LorrMaster42 wrote:Made a bunch of adjustments to it. Now the system can store multiple models that share the same design together (so straight walls and corner walls of the same design can be grouped together). I am now working on the actual design of the dungeon and how the models will be placed.
One thing I'm struggling with is how to go about creating the seed. I've looked up a couple random number generators, but I can never understand the code for it or how to get a good output from a range of values. I'm also not sure what is the best way to use the seed once I've got it working.
Ok, so pseudorandom number generators take a seed value, *modulus it by a prime number, and then run some more math to generate the next seed. Some prime numbers are better; for example, 7 is better than 5, because while 5 is prime, it'll also tend to have a shorter pattern; or what's called a "period". I could take a guess at why this is, but it'd only be a guess.
A bit more pRNG math. The reason it's pseudorandom is that, given a seed number and a pRNG formula, you will generate the exact same sequence each and every time, and the sequence will repeat. From start to finish is a "period". The smaller the prime number, and the less it fits certain traits prime numbers can have, the smaller the period. Again, I don't actually know what traits make a good prime number.
So, let's do a bit of math with 7. We'll take a number between [0, 20] for our seed value, modulus it by 7, multiply it by itself * 4, and then use that for the seed. This is almost certainly a really derpy pRNG.
Our seed value is... 7, according to the first website the Google search returned. An immediate problem occurs, because we just hit a repeating 0. How? Modulus 7 by 7, you get 0. (0 * (0 * 4))...Well, anyway. Change that to itself + 1; (itself * (itself * 4)). So 0 + 1; 1 * ( 1 * 4) = 4. Modulus 4 by 7 = 4.
4 + 1 = 5; 5 * (5 * 4) = 100. Modulus 100 by 7 = 2.
2 + 1 = 3; 3 * (3 * 4) = 48. Modulus 48 by 7 = 6
So we've just generated the sequence 0, 4, 2, and 6 from our initial seed value. Let's take it a couple steps farther...
6 + 1 = 7; 7 * (7 * 4) = 196. Modulus 196 by 7 = 0, which is unsurprising when your prime factors are 7, 7, 2, and 2. Heh.
So the period of this pRNG is 0, 4, 2, and 6. This is a terrible pRNG; it's period is 4 numbers long for a seed of 7, and all of them are **even.
And that brings us to the qualities of a good pRNG:
1) A good pRNG must have a "long enough" period for any seed number it could encounter.
2) A good pRNG must have a "random enough" period for any seed number it could encounter. That is, not only long enough, but also appear "patternless" over long enough periods of time. This includes the pattern of appearing patternless. Don't worry, I'll explain that latter, if you want to know. Just put it aside for now.
3) A good pRNG is made by mathematicians and programmers. That is, people who are both mathematicians and programmers, and whose knowledge in this area took years and, generally, a Ph.D to acquire. And sometimes teams of such people.
So don't worry about understanding it; just copy the code and implement it in your language of choice. At this point, you should have enough info to get the general idea, and while the facts, fields, and subjects behind a good pRNG are very complex and deep, a pRNG framework is just "modulo by prime number, then apply math to get next seed", possibly with some other math bits happening to the seed or return value. But the case of pRNGs is one of the very rare cases where it really is ok to just copy the code and implement it without understanding more than the basics.
Which brings us to cryptography, which relies heavily on pRNG, and which you should never copy code for. Because you will make a mistake. When it comes to cryptography, the rules are, 1) Don't touch anything; 2) Import a cryptographic library; 4) Don't touch anything; 3) Use it properly; 4) Don't touch anything.
Anyway, if you got this far, a pRNG that looks very patternless actually looks less random, because random numbers occasionally look like they have a pattern. In a population of 7 billion, someone rolling 5 1's in a row is not only inevitable, there's a very high chance it's happening right now. By the way, never play someone who knows as much about statistics as I do in a game of chance if money is involved. I don't gamble, but people who do can take you to the cleaners. There's nothing that combines such happiness and annoyance in quite the same way as learning that, predictably, the people you are playing monopoly with believe in "lucky dice", "lucky numbers", or "luck anything".
Worse interpretation of statistics I've ever seen: Constantly interpreting "unlikely" as "it doesn't happen". No; it just means it happens less often. "But it happened to me; therefore it's not unlikely". Ok; if we take a random sampling of a thousand other people, how many of them did it happen to, and what other factors might account for that?
* Integer divide and return the remainder.
** Let's not quibble over whether 0 is actually divisible by 2 or not; or whether or not it's a number at all. Real mathematicians get headaches from that.
Previous experience tells me it's very easy to misunderstand the tone, intent, or meaning of what I've posted. If you have questions, ask.
 LorrMaster42
 Posts: 66
 Joined: Thu Dec 24, 2015 12:09 am
Re: Hallway Test
So the takeaway from this is that statistics is very complex, its best to use someone elses pseudorandom number generator, and don't gamble.
As for using the seed, what is the best way to take a number from the seed and use it for the generation? Say I want to pick a random tile inside a twodimensional grid based on the seed. Does it matter how many digits I use and so on?
As for using the seed, what is the best way to take a number from the seed and use it for the generation? Say I want to pick a random tile inside a twodimensional grid based on the seed. Does it matter how many digits I use and so on?

 Posts: 839
 Joined: Mon Nov 30, 2015 6:32 pm
Re: Hallway Test
Yeah, pretty much.LorrMaster42 wrote:So the takeaway from this is that statistics is very complex, its best to use someone elses pseudorandom number generator, and don't gamble.
As for using the seed, what is the best way to take a number from the seed and use it for the generation? Say I want to pick a random tile inside a twodimensional grid based on the seed. Does it matter how many digits I use and so on?
Ok, now we come to "Perlin noise" It's called Perlin noise despite technically speaking being neither Perlin's original formula for noise, nor actually a noise generator, because it was invented by Ken Perlin. I'd highly recommend googling the name and reading more, in partly because "Perlin Noise" is a multidimensional pRNG. Use the Simplex version; that one produces more evenlydistributed noise.
Basically, all this comes down to is "your first seed value is your X coordinate; your second seed value is your Y coordinate". Then you pRNG them together to produce a combined seed value, then you pRNG that as a seed. Then you divide the result by the maximum number returned by the second pRNG, as a float; usually 2,147,483,647.0F. And if you don't know what that specific number, it comes down to most modern computers (certainly anything you'll run Unity on in the foreseeable future) storing integers as either 32bits or 64bits. Which means pRNGs nearly always return either a 32bit integer or a 64bit integer.
And since, for signed numbers, the first bit is used to tell whether it's negative or positive (1 for negative, 0 for positive), that leaves 31 bits for the actual number. Which means the highest 32bit signed number is 2,147,483,647. There is no need to memorize it; don't bother. For unsigned numbers, just type (2^bits)1 into a calculator; for signed bits, (2^(bits1))1. Or in this case, (2^32)1, or (2^31)1.
So now you have a 32bit float from [0, 1]. Use that as a height value, and you can make some pretty realistic heightmaps.
But you probably want to pick from an array; in which case, instead of dividing by 2,147,483,647.0F, just divide by the length of your array, and use the result to index your array.
Previous experience tells me it's very easy to misunderstand the tone, intent, or meaning of what I've posted. If you have questions, ask.

 Posts: 3419
 Joined: Tue Aug 25, 2015 1:54 am
Re: Hallway Test
Even if it's not strictly ontopic, I still love reading this stuff Thanks for the explanation Narf.
Farewell DFU community! My time here has been a joy.

 Posts: 839
 Joined: Mon Nov 30, 2015 6:32 pm
Re: Hallway Test
You're welcome.Jay_H wrote:Even if it's not strictly ontopic, I still love reading this stuff Thanks for the explanation Narf.
Previous experience tells me it's very easy to misunderstand the tone, intent, or meaning of what I've posted. If you have questions, ask.