Snowman Cometh

📅 2023-04-24

You know, maybe keeping a developer blog isn’t that great an idea in retrospect, it sort of reminds me of keeping a mental health mood tracker. You know, where you draw an emoji representing how you feel every day, and then at the end of the month you look back and realize you’re depressed like 80% of the time and holy shit, what is life? It’s just fucking rough out here, prices are constantly going up, long covid is a bitch, the government is squeezing, and the average person is running into walls like an NPC while refusing to wear a mask and screaming that covid is over while coughing the newest strain all over you.


So, some days, you just want to build a snowman. Admittedly, as an Australian, I have never built a snowman, so it's a conceptual desire. Growing up without a white Christmas and listening to every Christmas carol tell you how beautiful it was to be drenched head to toe in a meter of snow, or a yard, or whatever American's use. A fucking mile of snow. It sounded… wet, and cold, but still, nice. It’s odd to be nostalgic for a thing you’ve never done. Let's get to it.


The first thing I did is find some snow textures. I figured let’s give Runways text-to-texture another go, even though it has a history of not doing too well. Stable Diffusion seems to offer a better texture but without the normal, which isn’t terrible because a snow normal would be (and was) easy to find, but I figured lets get it done in one hit with Runway.



Not awful, but not really what I needed. So I altered the prompt a little to try and make it focus on creating plain snow. This was the second attempt.



Much nicer. Unfortunately the runway textures, while seamless, do repeat awfully most of the time, and this one was no different, but it would work for a base ground if it was set high enough. You can see I also adjusted the lighting and fog to feel colder and more isolated.



I then decided to just look for a better snow texture and found a few freebies online that didn’t repeat as horribly, and changed our Large, Medium, and Small Objects so that they had childed spheres, while turning off the box rendering on the parent.



Lovely snowballs, if I do say so myself. I then wanted to bring in our tile labyrinth generation, that was a script that I’m using in ‘Mirrors’ to generate the Labyrinth, so really all I had to do was change the look of the tile and we should have been gravy. Unfortunately, I had a bunch of trouble with the tiles not working correctly, probably because my head was a plate of friend noodles today. It took a little wrestling, but eventually I got the tile working, it didn’t look great, but it worked.



It looked more like a bouncy house or an inflatable raft or something though, so I decided to go online and see what I could find on CGTrader in their free section. It was, all in all, a pretty good haul. Initially, I couldn’t find any snow walls that worked, but I figured you could use a rock wall and just give it a snowey texture and it should work? I also found a nice little cabin, a snowman, and a cool archway. I spent around a half hour finding textures and making them all look nice in the lighting I was using, used some emission stuff, and some of our ‘Mirrors’ candles, and got something that I was pretty happy with.



Of course, I wouldn’t be content to just HAVE a snowman, that isn’t building a snowman, at all. So I took the pieces of the snowman’s face, and prefabbed them all separately as draggable rigidbody objects.



Thank you for your service, free snowman asset. I also went in and made the snow tile for the Labyrinth gen incorporate the walls, while cleaning up the code a little bit and adding some modularity via bools to allow certain processes to fire or not fire - specifically for wall checks, item spawning, etc, that I was using in mirrors.



I also centered my generator and attached it to our cabin, and lined it all up so we could start at the cabin and get to explore our new snowy labyrinth. I’m brushing over a lot of back and forth and little things I had to do all over the place but in the end we got there.




I now had to use our previous hallway asset generators to generate candles, snowballs, and snowman face objects. I don’t want to go into all the prefab collections and do a step by step, but I spent about an hour on this, as well as creating the end goal gate.



Everything was now in a state where I could create, in the very least, the bodies of the snowmen. I had to tweak and fuck around with the collider sizes, going in and out of playmode and adjusting to get it looking somewhat right, but eventually I got it feeling correct. And here is our faceless snowman.



I managed to mostly avoid code so far, with the exception of tweaking and cleaning the Labyrinth script, and now was the time to create the Snowman’s face. I thought about a few different techniques, and fielded GPT about how to go about it, but didn’t really like any of the suggestions. What I decided to do was prebuild the face as an asset, that could clip onto the small ball object, then deactivate all of the sections, store it in a script, and allow the script to turn them on one by one.



You can see that what I’m doing is - when ActivateRock is called, it randomly selects a rock from the rock prefabs (or coal, whatever) and then checks if it can activate it, if it can, it does, if it can't, it runs again. The carrot is simpler, because it’s just one object, so we just activate it when its called.


Now to call this, and instantiate the face prefab, we had to alter our Altar script. I gave the draggables two new bools, rock and carrot, and preset them all accordingly in the prefabs, and then dove into the script. What I needed it to do is, if it found that the draggable was a rock or carrot, it would Instantiate the face, if it didnt exist, store it for later, then run the correct activation. Then every subsequent item, the script would just use the stored face and activate it again. I also made sure the snowman would always face the player when building by correcting the rotation of the instantiated face against the cameras forward.



It was a bit of messing around to get the logic right, but the end result was worth it. Because sometimes, you just want to build a snowman.