Forgot Password

Hydrodynamics in Godot - Demo 2

Tuesday, February 12, 2019


Things have come a long way since the first demo! Here are some highlights:

  • My code is refactored into a module. The boat is a WatercraftBody (my counterpart to VehicleBody) which takes some inputs for the thrust and steering. Input is wired to steer the boat and control the throttle via GDScript.
  • There are no issues left with physics, as long as your boat sticks to some rules. For example, an extremely concave hull will definitely cause problems, and there's curently no way to create non-uniform weight for ballast. 
  • I found that a flat-bottomed boat slides sideways very easily, so I also added a rudder that is tied to the steering. It simply creates a pair of rotatable triangles that generate the same drag/lift forces as every other face on the hull. No physics hacks needed!
  • On land, the boat behaves the same as any other rigid body.


Having access to all the internal Godot classes means there are several things I could do to improve my code, mostly for readability, but maybe for some extra performance too. CPU usage isn't too bad, the game is using 20-30% of one core in the demo. This boat hull is 850 polys, and usually ~250-500 of them are evaluated for underwater forces each physics step, depending on whether you're planed out.

I've got a bunch of other polish work to make this more generally usable as well, but I think things are coming together nicely! Next demo will include more objects in the scene, maybe push the physics interactions a little harder. If anyone's got other potential use cases for me to try, let me know!





Be the first to comment.