Hallway Test

Show off your mod creations or just a work in progress.
User avatar
LorrMaster42
Posts: 65
Joined: Thu Dec 24, 2015 12:09 am

Hallway Test

Post by LorrMaster42 »

I decided to jump into blender and try out some modular hallways to see how they looked ingame. I made a straight, corner, three-way, and four-way piece and put them together.

https://youtu.be/nYuWz7c2ZDw

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Hallway Test

Post by Interkarma »

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.

User avatar
LorrMaster42
Posts: 65
Joined: Thu Dec 24, 2015 12:09 am

Re: Hallway Test

Post by LorrMaster42 »

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.

User avatar
LorrMaster42
Posts: 65
Joined: Thu Dec 24, 2015 12:09 am

Re: Hallway Test

Post by LorrMaster42 »

Got started on placing objects into Unity through scripting. Right now my script is running in an empty Unity scene and just places down 1-way tile pieces randomly along a 3-dimensional grid.

Image

Image

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!
Image

Image

Image

User avatar
LorrMaster42
Posts: 65
Joined: Thu Dec 24, 2015 12:09 am

Re: Hallway Test

Post by LorrMaster42 »

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.

Narf the Mouse
Posts: 833
Joined: Mon Nov 30, 2015 6:32 pm

Re: Hallway Test

Post by Narf the Mouse »

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.
Warning: This turns into a mini-rant 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 mini-rant.

:)

Ok, so pseudo-random 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 pseudo-random 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. :lol:
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.

User avatar
LorrMaster42
Posts: 65
Joined: Thu Dec 24, 2015 12:09 am

Re: Hallway Test

Post by LorrMaster42 »

So the takeaway from this is that statistics is very complex, its best to use someone elses pseudo-random number generator, and don't gamble. :D

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 two-dimensional grid based on the seed. Does it matter how many digits I use and so on?

Narf the Mouse
Posts: 833
Joined: Mon Nov 30, 2015 6:32 pm

Re: Hallway Test

Post by Narf the Mouse »

LorrMaster42 wrote:So the takeaway from this is that statistics is very complex, its best to use someone elses pseudo-random number generator, and don't gamble. :D

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 two-dimensional grid based on the seed. Does it matter how many digits I use and so on?
:lol: Yeah, pretty much. :D

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 multi-dimensional pRNG. :) Use the Simplex version; that one produces more evenly-distributed 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 32-bits or 64-bits. Which means pRNGs nearly always return either a 32-bit integer or a 64-bit 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 32-bit 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^(bits-1))-1. Or in this case, (2^32)-1, or (2^31)-1.

So now you have a 32-bit 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.

User avatar
Jay_H
Posts: 4061
Joined: Tue Aug 25, 2015 1:54 am
Contact:

Re: Hallway Test

Post by Jay_H »

Even if it's not strictly on-topic, I still love reading this stuff :) Thanks for the explanation Narf.

Narf the Mouse
Posts: 833
Joined: Mon Nov 30, 2015 6:32 pm

Re: Hallway Test

Post by Narf the Mouse »

Jay_H wrote:Even if it's not strictly on-topic, I still love reading this stuff :) Thanks for the explanation Narf.
You're welcome. :)
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.

Post Reply