What is Nour?
Nour is a game about playing with your food without the huge mess to clean up afterword. Designed by TJ Hughes the game challenges you to wreak havoc upon your dinner table. This takes various forms of course. The game presents no direct goals to the player, but instead allows them to simply have fun with their food.
Upgrading the MIDI Controller
TJ designed Nour to work with a unique input device: the Midi Fighter 3D, a MIDI controller that has a built-in gyroscope for detecting the rotation of the controller (perfect for flipping tables). With the a Unity plugin made by Keijiro Takahashi known as MidiJack, TJ was able to read input from the controller into Unity to allow each button to serve a unique action: spawning steak, popping popcorn, spinning a meat grinder, etc. However, the controller lacked something most modern controllers have by default: feedback to the player. I was brought on to update the plugin TJ was using with a new C++ DLL that would allow for communication to the controller via MIDI output. By doing this, TJ could then provide visual feedback to the player through blinking lights on the controller (and a neat display when in demo-mode, as seen below).
WOO Midi-Out is now working in Unity thanks to the brilliant @JeffOverTime!!
Jeff is looking for more work, so if you need any programming jobs done, he's your guy for sure! pic.twitter.com/H5tifEUTiL
— Tj 🍜 (@_Teejay5) January 25, 2018
Both TJ and I were pleased with the results.
Procedurally Generated Whipped Cream
One of the newer scenes in Nour allows players to play with a bathtub filled with ice cream. TJ wanted the player to be able to shoot whipped cream onto the ice cream and asked me to create a whipped cream generator. After clarifying with TJ that he wanted whipped cream from a can, I went out and bought a can of Reddi-Wip to begin testing. After spending a bit of time playing with real whipped cream, I felt like I had a decent idea of what was necessary to bring it into Nour.
Each strand of whipped cream is going to be somewhat unique in nature. The mesh for each strand, therefore, must be procedurally generated at runtime. While this sounds complex, it can be greatly simplified when broken down into a few steps.
First, I define the general shape of a horizontal slice of whipped cream to resemble a 5-point star. This allows me to simplify how we think about the vertices that define the shape of the mesh, as we can have a vertex at each angle on the star (as seen below).
If we then extrude that shape, you get something that vaguely resembles whipped cream, so we’re most of the way there already! Therefore, we just need to plot where these vertices exist in local space on each horizontal slice and then connect the horizontal slices with triangles to define the general shape of whipped cream. Essentially, these vertices are distributed in a circle around a point in local space where each vertex is some radius (r) away from the center of the horizontal slice (the radius is just shorter for the odd vertices). As such, a vertex’s position can be expressed as (x,z) coordinates where
x = r*sin(Θ)
z = r*cos(Θ)
And theta (Θ) is 360° divided by the number of vertices being distributed (360° / 10 = 36°).
By varying theta uniformly on a sine wave over time as you traverse from horizontal slice to horizontal slice, we can create a bit of randomness to make the strand look a bit more like actual whipped cream. Now it just needs to move like whipped cream.
Animating the whipped cream using rope-like physics seemed to be the simplest way to mimic the feel of a strand of whipped cream. Doing this in Unity is simple enough – several spheres are tied together as they are created using Configurable Joints. Each sphere represents a segment of the strand and Unity’s physics does the bulk of the work for us once we’ve defined a few parameters (mass of each segment, drag, breaking force, etc.).
We can use the shape of the connected segments to define the shape of the total strand through Bézier curves that use the position of each sphere as reference points. We then plot our vertices as we did before, but along the length of the curve. Although it would be ideal to update the position of these vertices through Unity’s Job system, Nour is currently not utilizing the beta version of Unity that supports the Job system. As a result, I instead batch the vertices with their related segment sphere, allowing us to only iterate over vertices still in motion. When a sphere hits static geometry, that sphere “sticks” to the geometry and halts the update on its related vertices.