• 0 Posts
  • 1 Comment
Joined 2 years ago
cake
Cake day: June 13th, 2023

help-circle
  • This looks great! I’m also working on a sailing game in Godot. I’m not trying to one-up you, but you may appreciate my input since I went through the same.

    The code looks really minimal which is a great benefit! Mine started out like that but became more complex and full of abstractions here and there to support more features and realism as time went on. In doing so, I think the simple code is really a strength you should try to preserve.

    One abstraction that I do think would make sense to add is the concept of an aerofoil as a separate node. You can model a sail as an aerofoil that can exert a force on the ship based on its own position. The positional part is important, since the mainsail can rotate around the mast, meaning that the position where the force is exerted is different all the time. Modeling it as a separate node would enable you to add multiple sails without effort as far as physics are concerned.

    You can take it a step further and model the rudder as a hydrofoil. Since they work the same as aerofoils with the exception of a different density constant (water vs air), they are both actually just instances of some foil class. In my game all sails, rudders and most keels are just foil objects. They check their own vertical position and use the density of water or air based on whether they are above or below the water. It saves a lot of duplicate code in the end and allows for easy modeling of your ship object.

    Side note: using RigidBody3D::apply_force() with a second argument (position) makes it easy to add the force exactly where it is supposed to be exerted. You don’t need to compute the torque yourself as the physics engine will do that.

    A note on keels: during my experimentation with sailboat design (in the game), I learned that the keel/centerboard is actually really important not just for “going straight” but also “going fast”. The reason for this may be quite surprising: a keel does more that just prevent lateral movement. Since it’s a hydrofoil, it interacts with the water and creates its own lift and drag. The lift component of the keel is just as important as that of the sails for building up speed. If you make the centerboard retractable you will be able to see this difference for yourself in your simulation. So I definitely recommend adding a keel to your game and checking out the results.

    All in all I’d like to say thanks for sharing! I will be following your project.