Unity Experiments in random NPC generation

InfiniTales

Newbie
Aug 11, 2021
38
24
In a previous thread, I wondered about possibilities to procedurally randomize content in modern game engines. So I've been experimenting with importing DAZ models in Unity and see what Blendshapes and procedural textures (Substances) can do. Here's what I ended up with after a week or two.

As you can see, I'm using a stylized/cartoony look. I put together a collection of DAZ Morphs that allow varying the model, and in Substance Designer made a substance from scratch. Then I made a script to randomize it all. I've never programmed in (Unity's) C#, I'm still finding my way around.

Animating these models *should* still be possible even with the different mesh body sizes using methods that modify/retarget existing animations in runtime. It's on my to do list for this experiment, but first I want to tweak the texture randomizer more, add different hairdo's,... I did already succeed in getting a clothes set, making sure all relevant morphs also exist for the clothing items, and have them follow the randomized character mesh morphs.

Having fun! =D

unity_techdem_0822.gif imen
 

Tompte

Member
Dec 22, 2017
215
155
Looking good!

Here's some advice that helped me when I was doing something similar: try to incorporate a Gaussian distribution (bell curve) if you aren't already. I found it gave me more control over the random values because I could set a minimum, maximum AND a good average. It's also closer to what we'd expect to see in nature.

In my game I wanted to randomize penis lengths and at first I just rolled a value withing a min-max range. But because there was a uniform probability for any penis size I got extreme results more often than I wanted to, unless I restricted the range. What Gaussian distribution does is to let more rolls land within a "normal" range of values while occasionally giving extreme results, which I personally think is more interesting.

The easiest way I've found to get such a distribution is to roll multiple values and average them, like this:
Code:
float Gaussian(Randomizer rng)
{
    const int k = 5;
    float r = 0.0f;
    for (int i = 0; i < k; ++i)
        r += rng.Float(); // returns [0..1)
    return r / k;
}
0.0 = minimum extreme (very rare)
0.5 = average (common)
1.0 = maximum extreme (very rare)
 
Last edited:

InfiniTales

Newbie
Aug 11, 2021
38
24
Thanks! =D

Thank you for the clean function, I'll likely use it somewhere.

I did indeed already made the code so it separates the morphs in common, uncommon, rare,... occurences by chaining if.. then... elses. Same for colors: 75% chance for brown tinted eyes, 10% blues, 5% amber, 2% green etc... Based on statistics I looked up online.

I'll probably rewrite most of it, because now I'm finding I didn't really implement a link between skin colors and eye/hair colors. Blonde hair & blue eyes should be much, much rarer for darker skintones, and so on.

I also need to link the round face morphs to the heavier bodytype morphs.

So far my code is *really* dirty! I just try code till it works no matter how and move to the next challenge. Clean efficient code will be something for when I'm more used to the c# syntax. I'm not used to the very rigid variable declaration rules, needing to put multiple variables in lists and tuples, etc. lol