For this week's Sunday Experiment, I'm revisiting something I briefly attempted during the original jam dev session of When Pigs Fly. The first iteration of the map in When Pigs Fly had a lake, but I ended up removing it for a couple reasons. First, I simply didn't have time to add a buoyancy system. Second, the animated water I made was pretty resource hungry, and I didn't have time to optimize it.
Since the jam is over and I'm no longer restricted to always writing new code, I'm now able to take advantage of some of my previous work. This morning I grabbed the water system from my WIP low poly terrain generator and the buoyancy systems from Hoist and threw them in to WPF. An hour or so later I had a working sea-plane using blue barrels as floats.
The water object deforms its mesh based on Perlin noise. It has a public function called GetDepthAtPosition that takes a Vector3 position and returns a float depth. It works very simply by comparing the y value of position with the perlin value at the (x,z) values of position. We'll use this function later to calculate the buoyancy forces on the barrels.
Each barrel has a few child "Depth Checker" gameObjects. The positions of the children are fed into the Water.GetDepthAtPosition function to determine their depth. That value is then used to calculate the buoyancy force using archimedes principle. Doing it this way causes the barrels to react correctly to waves.
I then quickly threw together a particle system that emits when the average of a barrel's depth-checker children is greater than 0. It also sets the velocity and size of the particles based on the velocity of the rigidbody.
For the second week in a row, my Sunday Experiment has resulted in something that I really want to add to the game. This water system is too simplistic though, so it won't show up in v0.3 as is. In fact, I'll probably have to wait until I flesh out a couple other systems in the game before I can add this one. While it works in this example, I know that players would find a way to break it. Off the top of my head, I can think of people trying designs with rudders on the back of their floats. In the current system, they would act like they were normal rudders, moving through air rather than water. For this to work, I'll have to find some way to integrate the depth-checkers with the aerodynamics system.
Update: You've seen the Spruce Goose. Now meet the Plywood (and plastic) Pig!