April 28, 2017

Short April Updates - from forest fires to foam skirts

0 comments

Forest Fire

Many years ago I took a class in Differential Equations. One of the assignments was to simulate the evolution of a forest fire and the result was displayed on a graph. The problem was that you only got the end result and couldn't see how the fire evolved to get to the final result. A few years later I learned Unity, and decided to see if I could simulate a forest fire while at the same time see how it evolved. And it turned out I could.
The forest fire worked, but the visuals didn't. The first problem I had was smoke. A forest fire is large and you need a lot of smoke to cover the entire area - and that is not good from a performance perspective, and the resulting simulation was running in like 3 fps (30 fps is the goal). Luckily, both Unity and I have improved our skills.
The first thing I improved was to replace the fire particles with a glowing-ground-shader. Most of the time, you can't see the fire because of all the smoke, so by having just flat fire instead of fire particles makes no difference. I also decided to use animated smoke particles from Unity's free library of particles: Free VFX Image Sequences & Flipbooks. By using animated particles, the smoke will look more thick and you can use less particles to achieve the same result.
The second problem I had when I created the original forest fire was similar to the smoke problem: a lot of trees will decrease the performance of the simulation. To solve that problem when I created the original version was to combine all trees into a single mesh. This is also a complicated solution because it will make it much more difficult to remove the trees as they burn down. Luckily I could now replace all that code with a single shader called GPU instancing, which is something Unity recently added. If you add one of those materials to objects with the same mesh, Unity will automatically combine them, and the performance will improve. Anyway, this was the result:


Shaders

As said in the forest fire update I added an animated glow shader to simulate the fire. The reason was that I've also improved my shader skills. The first shader skill I learned was Interior Mapping, which is a technique used to simulate floors in buildings. The second technique was Parallax Mapping, which is a technique not that different from interior mapping, but you can simulate more "organic" deformations, such as this:


Tesla Simulator

I few years ago I made a Tesla Simulator to market a book I wrote about a guy called Elon Musk. It was available to the public through Unity's webplayer, which you could run directly in a browser like Chrome or Firefox. The problem now is that most browsers have stopped supporting the webplayer, so I had to make an offline version. At the same time I've cleaned up a lot of silly coding mistakes I made, because the Tesla Simulator was the first project I made in Unity - and I've apparently learned a lot since then.

"Make a boat" tutorial

One of my most popular Unity tutorial I've made is Make a realistic boat in Unity. What the tutorial didn't have was how to add foam to the boat, and I've thought a lot about what the best way is to add foam to a boat. Then I found this tweet:


...which was a cool idea on how to add foam, so I decided to implement it: Add foam. To make that work, I had to learn a technique called Convex Hull, which I wrote a separate tutorial on how to implement: Find the convex hull of random points.

April 24, 2017

Aircraft Carrier Simulator - or how to make a game in 48 hours

0 comments
Ludum Dare was on this weekend. It's a competition where you are supposed to make a game during 48 hours, and you may win fame and glory if you make a good game, so no money is involved. But people have come up with good ideas by participating in the competition, and they have later modified the game, sold it, and thus made money from it. One example is the game Broforce.

There are two different competitions going on at the same time: Jam and Compo. If you are participating in the Compo, you have to make everything yourself, including the textures, models, and sounds. Not a single piece can be found by googling. This is a however a gray-zone. Are you allowed to steal an engine sound from a YouTube video, or do you have to record it yourself? While making my game, I watched a Twitch streamer who was also participating in the competition, and he had a really hard time making sounds for his game. You could see on the stream how he squeezed a coca cola can to make a specific sound, so you have to be a little creative. I usually get my sounds from this site: Bfxr, which is a site you officially are allowed to use. I usually click a million times on the "generate-random-sound-button" until I find something useful and then I modify the sound in Audacity.

Each Ludum Dare competition has a theme. The theme this time was "A small world," so I decided to make an Aircraft Carrier Simulator. You can say that an aircraft carrier is like a small world because you can find everything you need on the ship. A few years ago I made an airport simulator for the same competition. It failed miserably, and I have hopefully improved since then.

This was my 9th Ludum Dare competition. One thing I have learned is that sleep is important. The competition begins at 3 am local time and ends 48 hours later. I have learned that sleeping until like 7 am, work the entire day until like 10 pm, and then go do something else like watching a streamer while thinking about the game until 12 pm which is bedtime, and then repeat the process the next day is the way to go. Anyway, this was the result:





The game idea is that you are in command of this aircraft carrier's aircraft operations. It's your responsibility to steer the aircraft so they can refuel, land, and launch from the catapult so the enemy is not coming closer than zero meters from the aircraft carrier. If the enemy get any closer, you fail! The more aircraft you have in the air, the more difficult it will be for the enemy to come closer. If you think it looks and sounds interesting, you can test the game (and download the source file) here: Aircraft Carrier Simulator.