This morning I worked on buoyancy. This is the set of systems that let the player put rectangles in the level editor that represent water or other fluids that things should float in and get additional drag inside of.
This strategy here is to create a custom Area2D sub-class which notifies objects which enter it that they have entered or exited into a region of Buoyancy. A second helper class, meant to be used on Buoyant objects keeps track of which Buoyant areas an object is currently in and calculates the appropriate Buoyant force based on those regions customizable Buoyancy and the intersecting area. Because of that latter bit objects naturally float at some level on the surface of a buoyant area because the buoyant force is proportional to the submerged area and so approaches zero as the object leaves the area.
The BuoyancyHelper class is a good example of “composition is better than inheritance” (I think) and I’ve used this strategy in this version of the Ghost game a lot. A lot of functionality that many nodes might want to use is just split off into nodeless classes.
I guess next on the agenda here is a splash effect.

