Forgot Password

Hydrodynamics in Godot - Demo 3

Tuesday, February 19, 2019


Another week, another demo! The major addition this time is the waves. It was too expensive to calculate the wave height at every single point on the boat, so I had to compromise a little. I take the plane of the boat's bounding box and subdivide it into four quadrants, which requires sampling the wave height at only 5 points. Think of it roughly as a sheet of paper creased in half the long way and the tall way, and it only bends at the creases to conform to the waves. To generate the underwater part of the boat, each face gets assigned to the quadrant directly above it and clipped to that plane only. It seems to work well with everything I've thrown at it so far.

Underneath the hood, there are a handful of improvements as well. Buoyancy no longer relies on a volume calculation of the submerged mesh, which means concave hulls, multi-hulled boats, etc should work now. I've also reworked my code to make better use of Godot's other internals, which seems to have improved the performance. This demo has 3 boats (two of them without any hull optimization) and 5 cubes, and my CPU usage is still under 50% of one core. (For reference, the ocean demo project where I stole the water from runs at 22% on its own.)

I've got more features I want to add, but I think this is a good point to draw a line and make a first release. I need to finish cleaning up my code, write some documentation, and make a slightly more polished version of the demo for release as well... I'll definitely have the code with some basic docs released this week, with the playable demo to follow afterwards.





Be the first to comment.