Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Help me with my sailing ship, please

Discussion in 'Scripting' started by epochplus5, Feb 25, 2021.

  1. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    Hi guys

    I have a top down 2D old sailing ship. I have a wind direction pointer (Whatever thats called, a weathercock?)

    The idea is that if the wind is blowing from the North, the ship will travel fastest South, the opposite obviously. and the more off center you go the slower the boat goes, and if facing a direct wind, you crawl. The wind also has strength rated from 1 to 10, 10 being the hardest.

    I have the player ship rotation captured in a variable on the player script and the wind rotation needle on another. I need to get these two together and compare them and then depending on there positions apply the correct amount of force from the back of the boat.

    whats the best way to tackle this?
     
  2. reachdabeach

    reachdabeach

    Joined:
    Jan 28, 2021
    Posts:
    70
    Having some sailing experience, I wanted to chip in that running down wind is not the fastest point of sail. It's actually the beam reach; perpendicular to the wind.
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This ^^^

    The design of the sails is also important. Square sails are better down wind. Lateen sails better in a cross wind.
     
    SparrowGS likes this.
  4. reachdabeach

    reachdabeach

    Joined:
    Jan 28, 2021
    Posts:
    70
    Last edited: Feb 25, 2021
    SparrowGS and Joe-Censored like this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    Once again Epoch, trying new stuff... SO GOOD! It's like I'm starting to look forward to "What's Epoch up to now!?" every day in the forums. Grab the popcorn sit down and see what you're up to.

    For the purposes of simulating, one approach is to have a lookup table for how much static thrust the wind hitting your sail produces based on its incident angle to your sail airfoil, say ranging from zero (straight headwind) around to 180 (tailwind), with a peak mostly in the middle, "beam reach."

    Neglecting the billow of the sail, which effectively changes the nature of its airfoil (NACA has tons of research on this), you could get a basic simulation going with a radial lookup of angle to thrust.

    Building more on what our resident sailor @reachdabeach says, sailing is quite complex. You can find wind diagrams for any given boat and wind condition, and from those decide which angle gives the best boat speed.

    Sails are just like airplane wings, with some extra wiggliness because their shape can be radically changed by simple rope controls, changing the wing camber primarily, but also changing the effective chord.

    There's also the interaction with the keel to consider, but let's leave that out for now.

    Remember though, thrust is applied in the direction of change of wind velocity, NOT in the forward direction of the boat necessarily. In other words, if you're sailing north and the wind comes in from heading 090 and leaves your sail as if it had come from 130, you're imparting thrust as if there was a finger pushing on the boat FROM heading 160 to heading 340. Draw it out on a compass rose and think of the wind as having mass that your sail is deflecting.

    For you to make meaningful headway, a large enough component of the thrust must be going forward. Since going north you are heading 000/360, 340 is close enough that such a beam reach will produce good headway from that force.

    Because your sailboat's forward speed ALSO contributes to the effective incoming wind angle (also known as "incident angle"), as you gain forward speed in a constant wind condition, the apparently wind incoming angle will change by moving slightly forward, reducing the thrust.

    For true "beam reach" condition you want the relative wind coming in at 110 and going out at 280 heading, which puts the effective force vector at 000, nothing wasted laterally, pushing you 100% ahead.
     
    Last edited: Feb 25, 2021
  6. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    LOL shows how much I know. Thanks for the pointers guys! I'm not so much experimenting with a simulation as much as a fun 2d arcade type cannonball shooter. So accuracy isnt paramount.

    Should i still use a lookup table?
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    What I chose to do in my game was for each point of sail define a max speed, and I just type it directly into the inspector. Gives me more control of how fast I want the ship to go with each wind direction, which I think makes it more interesting than applying a percentage from an optimal direction. You're using variable wind speed, while I'm not, but you might go about it the same way.

    From my own editor of one of my ships
     
  8. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    Thanks joe, any chance i can see your game :)
     
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Sure, the Steam page is here, and my dev blog for it is at the bottom of all my comments. The listed release date is wrong, cause at the rate I'm going it isn't going to be out until next year. I'm sure I said the same thing last year ;)

    Broadside: Perilous Waters on Steam (steampowered.com)

    If you were asking for a beta key for it, send me a private message.
     
  10. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    looks absolutely amazing!!!
     
    Joe-Censored likes this.
  11. reachdabeach

    reachdabeach

    Joined:
    Jan 28, 2021
    Posts:
    70
    That is a serious tall ship game. Very nice! I notice you have close hauled on your inspector; can any of those ships actually point that high? That gets into the even crazier physics since increased speed into the wind means increased wind...
     
  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    I always thought that IRL 20 to 25 was pretty near luffed.

    I just can't see 14, but maybe in the game it plays better?
     
  13. reachdabeach

    reachdabeach

    Joined:
    Jan 28, 2021
    Posts:
    70
    I just meant that I didn't even know close hauled was doable in brigs or full rigged ships. But my experience is in smaller sailboats; trailer sailors and class racers.
     
    Joe-Censored likes this.
  14. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    When I originally started working on the game, I had the idea of going for maximum realism I could reasonably pull off as a solo indie dev (I'm a less experienced sailor than you, but I can sail your average 24 footer around the San Francisco Bay by myself just fine, so I've mostly got a good idea what that means at least). After playing it though I quickly discovered that realism in a sailing game actually isn't very fun. So I've taken some liberties for the sake of it being a game.

    So all the ships can go much tighter into the wind than I believe they are really capable of, because having a huge dead zone into the wind means you have to tack a lot more times to make headway into the wind. My ships move incredibly faster than reality because moving a large vessel at the speed of a bicycle turned out to be mind numbingly boring when traveling any further than very short distances (primarily because the game world is extremely large). I also allow the player to always be able to turn the ship, even when stopped, so they should be able to get themselves out of situations which might otherwise require a tug or an onboard motor today, because getting stuck and having to wait for the wind to shift for a half hour was no fun at all. Things like that.

    So as far as speeds at different points of sail, some of that is for the sake of the game. I wanted some ships to do better running, some to do better in a cross wind or even going tight into the wind (correlating to the types of sails the ship uses), to add a bit of strategy into how a player may approach an engagement depending on their ship and their opponent's ship. If you're out classed, and you need to make a run for it, heading in a direction where the wind is optimal for your ship but not for the enemy can increase your chances. That kind of stuff.
     
    Last edited: Feb 26, 2021
    Kurt-Dekker likes this.
  15. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,878
    Gotta say joe, mighty impressed. Knew you were making a sailing game, but never imagined it would be an MMO. Yet yours actually looks like it will get released and work, which is a miracle given the usual MMO ideas that come and go by the day here.

    Ill be playing it thats for sure!
     
    Joe-Censored likes this.
  16. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Yeah when I started, I drastically underestimated the amount of time it would take (like everyone who wants to build an MMO), and sunk cost fallacy kept me going ;)
     
    Last edited: Feb 26, 2021
    MadeFromPolygons likes this.
  17. reachdabeach

    reachdabeach

    Joined:
    Jan 28, 2021
    Posts:
    70
    Don't sell yourself short. I am not sure I would have an easy time single handing a 24' boat around the bay. I had a Newport 17, which is a smallish trailer sailor (my kids loved the tiny cabin when they were little) and crewed a lot on class racers. There is (was? I haven't been in a while) a local sailing club that meets on Sundays at a nearby res. I could just show up and someone would take me. A couple of guys had Flying Scots and would come solo.

    I know more about larger boats from reading historical novels that are supposedly accurate. Cutters would beat into the wind to outrun larger boats. They had the same issue with time. The cat and mouse game a ship would play when it was downwind was exciting; staying out of cannon range trying to slip by, unable to outrun the larger ship until it got past. But that excitement was tempered by how long it could take. Sometimes they would end up dowsing all the lights at night and tacking off in some near random direction.
     
    Joe-Censored likes this.